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
0
votes
1 answer

What is the benefit of NSScanner's charactersToBeSkipped?

I have the string @" ILL WILL KILLS ", and I'm using NSScanner's scanUpToString:intoString: to find every occurrence of "ILL". If it's accurate, it will NSLog 4, 9, and 14. My string begins with 4 spaces, which I realize are members of the…
John Sauer
  • 4,411
  • 1
  • 25
  • 33
0
votes
2 answers

Extra characters in NSScanner (objective-C)

I have a small problem parsing a string in NSScanner. I've read other SO posts on this, but cannot solve this dumb issue. I have a string like this "the first word is not = to the second word" My code is: NSString *seperator = @" ="; NSCharacterSet…
ICL1901
  • 7,632
  • 14
  • 90
  • 138
0
votes
1 answer

iOS How to get all words coordinates in PDF page

I have looked through many tutorials and usually stack users trow links to the pdfkitten, but as I've tested it I have not satisfied with result. So the search does not work with multiply word and etc. So what I am looking for I need to get all…
Matrosov Oleksandr
  • 25,505
  • 44
  • 151
  • 277
0
votes
2 answers

Using NSScanner to separate string into NSArray by comma

Does anyone know how i can use NSScanner to separate a string by comma into an array EXCEPT when a comma is embedded within quotes? Before i had been using: NSArray *arrData = [strData componentsSeparatedByString:@","]; However i have quotes…
JH95
  • 489
  • 1
  • 7
  • 24
0
votes
1 answer

Possible use of NSScanner to separate data

I am parsing some XML data and one of the elements contains several URLs that are separated by commas which point to JPG files. How would I go about separating each URL from the string and assigning it to a variable so that I can pull individual…
Green Developer
  • 187
  • 4
  • 18
0
votes
2 answers

Convert NSString with NSScanner

I have a string formatted like this : Oy\U00e9\U00e9 Oy\U00e9 So, I found something in some forum and tried to adapt it. This is what I use : // To keep whiteSpaces safe string = [string stringByReplacingOccurrencesOfString:@" "…
Ritooon
  • 155
  • 12
0
votes
2 answers

Getting multiple tags from html source code in Objective-C

I have extracted the source code from a website but i would like to display the strings of three urls. I have managed to strip the code so the only url's are the ones I need. How can I get the three strings in an array. The URL's look like this:
Andrew Ho
  • 618
  • 9
  • 21
0
votes
1 answer

Using Objective-c to parse information from JSON url

I'm trying to write a piece of code that will make use of reddits JSON format. I intend to visit the url: http://www.reddit.com/r/pics/new/.json, search for the string: "title": " and write everything from there till the next apostrophe " to the…
0
votes
3 answers

Extracting price from string

I am looking for a short and convenient way to extract a product's price from NSString. I have tried regular expressions, but always found some cases where did not match. The price can be any number including decimals, 0 and -1 (valid prices: 10,…
user-123
  • 874
  • 1
  • 13
  • 34
0
votes
1 answer

Read new lines with NSScanner

I'm trying to read the characters between words in a string. NSCharacterSet* whiteSpace = [NSCharacterSet characterSetWithCharactersInString:@" \n\r\t"]; NSScanner* testScanner = [NSScanner scannerWithString:@"space newline\n space space…
user714171
  • 363
  • 1
  • 3
  • 12
0
votes
0 answers

NSScanner only working with non-initialized variables. Why?

The following code works, but produces warnings about non-initialized variables. The code parses a string representing a molecule, such as @"2C12;5H1;1O16". It checks that it is correctly formatted and that all the components are valid isotopes. …
0
votes
3 answers

NSString remove duplicated substrings

How can I remove duplicated substings from string? For ex. I have: aaa,bbb,ttt,bbb,rrr. And in result I want to have aaa,bbb,ttt,rrr (deleted duplicated bbb). I hope for your help. Thanks.
LightNight
  • 1,616
  • 6
  • 30
  • 59
0
votes
4 answers

How to filter a string after a particular character in iOS?

I want to filter string after character '='. For eg if 8+9=17 My output should be 17. I can filter character before '=' using NSScanner, how to do its reverse??? I need a efficient way to do this without using componentsSeparatedByString or creating…
Francis F
  • 3,157
  • 3
  • 41
  • 79
0
votes
2 answers

How to change a string like "$123.4" into floatValue

Just like the title : how can i change a string @"$123.4" into a float value 123.4 in iOS NSString *string = @"$123.4"; Any help will be appreciated. Thanks in advance. Giki
Giki
  • 11
0
votes
2 answers

Convert string to timer, and add 1 minute to the string

If I have a string from key and the string is a timer (12:00) how to add 1 minute to the timer, so the label will show 12:01: NSString string = [subDict objectForKey:@"1"]; NSScanner timeScanner=[NSScanner scannerWithString:string]; int…