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

Proper validation with [NSScanner: scanInteger] in Cocoa

I am converting a string to signed integer via NSScanner:scanInteger, but it seems to be accepting values such as '123abc' as '123', instead of throwing a error on invalid input. I can do my own custom validation, but would prefer to find an API…
Locksleyu
  • 5,192
  • 8
  • 52
  • 77
-1
votes
2 answers

Decoding SWIFT model class from text file

I have a model class class User{ var name:String var number:Int } i have the details of this downloaded as a text file with format firstname:John rollnumber:234 5 How can i right a custom decorder for this. NB: the keys 'firstname' 'rollnumber'…
Raon
  • 1,266
  • 3
  • 12
  • 25
-1
votes
1 answer

Why is NSScanner not finding the 1st occurrence of the target string?

I have a Obj-c app that was working; now it isn't. This is the portion of the string that I am trying to parse:
SpokaneDude
  • 4,856
  • 13
  • 64
  • 120
-1
votes
1 answer

NSScanner not scanning long numeric string into number

I have a string "999999999999528106" and I am passing it to NSScanner but the output is not correct. I get 2147483647 as result. I guess the big size of my string is not fitting into the NSInteger. Any clue NSScanner *aScanner = [NSScanner…
Abhinav
  • 37,684
  • 43
  • 191
  • 309
-1
votes
2 answers

How to Separate NSString Data

I Have one NSString* string; String = "ID: 12 34 56 78 Class:C" Now i want to distinguish the ID data in one variable and Class data in another, How can i separate this two from single String I have used : NSScanner* Scanner = [NSSCanner…
-2
votes
1 answer

Search for a string in an if statement with an NSScanner?

Is it possible to search for a string in an if statement with an NSScanner? I wanted to search through the html of a page and then if there is a certain piece of code, do something and if not, do something else... Thanks!
pixelbitlabs
  • 1,934
  • 6
  • 36
  • 65
-2
votes
1 answer

Need to extract specific text out of NSString

I am pulling user information from my server's database. When the user is found in the database, an object is returned to me and when I NSLog the object it looks like this: ( " {\n \"Phone_Number\" = 5859921091;\n…
user3344977
  • 3,584
  • 4
  • 32
  • 88
-2
votes
2 answers

Using NScanner to parse CSV File to Dictionary Array

I've created an iPhone app that has a dictionary array of locations (lat,long,point). I created the array by manually entering each value. myLocationArray = @[ @{ kStation : @"1", kLatitude :…
JBeesky
  • 309
  • 2
  • 14
-3
votes
1 answer

Calculate characters up to %@ in NSString

I have a variety of NSStrings that could be for example: NSString *string = [NSString stringWithFormat:@"Item Used %@ times",item.numberOfUses]; or NSString *string = [NSString stringWithFormat:@"Created %@ items",item.count]; Main point being,…
f.perdition
  • 205
  • 2
  • 14
-4
votes
2 answers

I want to remove static text from string - iOS

Hi I have a News Reader and I keep getting a string like this - two New York police officers shot dead in 'ambush' I want the string two New York police officers shot dead in ambush How can I scan from & to ; and then delete occurrences…
-4
votes
2 answers

Using NSScanner

I am trying to scan a text, but I do not understand how it works, could anybody help me??
1 2 3
9
10