Questions tagged [nsscanner]

The NSScanner class is an Objective-C class implemented in the Foundation framework, starting from Mac OS X 10.0. The NSScanner is a highly configurable tool designed for extracting substrings and numeric values from loosely demarcated strings.

The NSScanner class is an abstract superclass of a class cluster that declares the programmatic interface for an object that scans values from an NSString object.

An NSScanner object interprets and converts the characters of an NSString object into number and string values. You assign the scanner’s string on creating it, and the scanner progresses through the characters of that string from beginning to end as you request items.

Because of the nature of class clusters, scanner objects aren’t actual instances of the NSScanner class but one of its private subclasses. Although a scanner object’s class is private, its interface is public, as declared by this abstract superclass, NSScanner. The primitive methods of NSScanner are string and all of the methods listed under Configuring a Scanner. The objects you create using this class are referred to as scanner objects (and when no confusion will result, merely as scanners).

You can set an NSScanner object to ignore a set of characters as it scans the string using the charactersToBeSkipped property. Characters in the skip set are skipped over before scanning the target. The default set of characters to skip is the whitespace and newline character set.

To retrieve the unscanned remainder of the string, use [[scanner string] substringFromIndex: [scanner scanLocation]].

146 questions
1
vote
1 answer

NSScaner - can not get HexFloatValue?

I'm trying using the following code: float fValue = 0; NSScanner *scanner = [NSScanner scannerWithString:@"0x41CC8937"]; [scanner scanHexFloat:&fValue]; Hex 0x41CC8937 = float 25.567. But I'm getting fValue = 0x4E839912 (float 1103923456.000000),…
TESTer
  • 55
  • 6
1
vote
2 answers

How to use an NSMutableString in a method that takes an NSString?

NSScanner takes a pointer to an NSString: NSMutableString *myString; ... [scanner scanUpToCharactersFromSet:charSet intoString:&myString]; [myString appendString:@"hello"]; But myString is mutable, so I get an error when I try to do an append…
Joey FourSheds
  • 479
  • 1
  • 7
  • 18
1
vote
4 answers

Finding first letter in NSString and counting backwards

I'm new to IOS, and was looking for some guidance. I have a long NSString that I'm parsing out. The beginning may have a few characters of garbage (can be any non-letter character) then 11 digits or spaces, then a single letter (A-Z). I need to…
Jonesopolis
  • 25,034
  • 12
  • 68
  • 112
1
vote
1 answer

Including the final character in text output from a NSScanner

I am using a NSScanner to detect text bound by [square brackets] in a string, and convert it into HTML hyperlinks. I hope to turn convert this text in the following way: This [is an] example of the [text] I'm using should convert to This
CaptainProg
  • 5,610
  • 23
  • 71
  • 116
1
vote
2 answers

Yet another NSScanner characterSetWithCharactersInString newb

Let's assume I have a string ("G00 X0.0000 Y0.0000") and I need to to parse its contents. Here is my code: NSCharacterSet *params = [NSCharacterSet characterSetWithCharactersInString:@"XY"]; //setup the scanner NSScanner *scanner = [NSScanner…
1
vote
1 answer

Parsing Class writes last item twice

I am helpless. I parse this text... HELLO World digit wow hellonewitem lastitem with an instance of NSScanner: -(NSMutableArray *)parseTest { if…
Riscie
  • 3,775
  • 1
  • 24
  • 31
1
vote
1 answer

Unable to print NSString assigned with NSScanner

I am trying to scan for a specific string in an html file, assign it to an NSString then do things with the NSString. If it matters, I am doing this in Cocos2d. My code looks like this: NSScanner *scanner = [NSScanner scannerWithString:…
TheDanman
  • 98
  • 1
  • 8
1
vote
3 answers

closest thing to NSScanner in Java

I'm moving some code from objective-c to java. The project is an XML/HTML Parser. In objective c I pretty much only use the scanUpToString("mystring"); method. I looked at the Java Scanner class, but it breaks everything into tokens. I don't want…
itgiawa
  • 1,616
  • 4
  • 16
  • 28
1
vote
1 answer

Parse Image and Extension From URL Objective C NSScanner

I have a program that will be grabbing a image from our server for the app, however we want to save the image onto the iOS app for caching purposes. The url would be similar to this. http://www.example.com/image/app_name/mypicture.png I need a way…
Dfranc3373
  • 2,048
  • 4
  • 30
  • 44
0
votes
1 answer

Remarkable behaviour by NSScanner

I have the following string in an NSTextView: Horus avenged his father Osiris There are two tags assigned to this, Horus and Osiris. I use NSScanner to scan the string for both tags and highlight them with a yellow background when found. The code…
Roger
  • 4,737
  • 4
  • 43
  • 68
0
votes
1 answer

NSScanner working on WiFi but not 3G

I have set up an NSScanner to work on the tap of a UIButton with the following code: -(IBAction)doLoadTTData { NSString *Period1String = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource: @"Period1String" ofType: @"txt"]…
pixelbitlabs
  • 1,934
  • 6
  • 36
  • 65
0
votes
1 answer

How can I search for a string in a .txt file for NSScanner?

Possible Duplicate: Find next match of a phrase with NSScanner I currently have the following code to get a certain piece of code from the UIWebView: NSURL *requestTimetableURL = [NSURL…
pixelbitlabs
  • 1,934
  • 6
  • 36
  • 65
0
votes
1 answer

Objective-C - Using NSScanner to read string?

SO I am trying to read content of an html string. [scanner scanUpToString:@"<" intoString:&result]; What is the fastest way to read the content into string but ignore the last character which in this case is "<". I don't want to do…
aryaxt
  • 76,198
  • 92
  • 293
  • 442
0
votes
0 answers

Easiest way to perform a deep copy of a string to pass to a scanner?

I am following the code shown here : Convert hex string to long to read a long from a string. In their example, they have a hard-coded string, but in my own context have another value I am taking the string from and that value seems to change but I…
ahSatan
  • 1
  • 1
0
votes
1 answer

Does scanCharactersFromSet:intoString: create an autoreleased string?

While using Instruments, it seems like there is a leak coming from this method (scanCharactersFromSet:intoString:). I am not releasing the variable that gets put into intoString Does this method create a retained or an autoreleased string in the…
Alex
  • 7,432
  • 20
  • 75
  • 118