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

When to use NSScanner vs. componentsSeparatedByCharactersInSet: to tokenize NSString?

I need to tokenize many strings on an iPhone. Obviously, resources are at a minimum. I have been using componentsSeparatedByCharactersInSet: to tokenize my strings, but it is slow. Would it be better to use NSScanner? What, generally, are the…
Jason
  • 14,517
  • 25
  • 92
  • 153
1
vote
1 answer

NSScanner Remove Substring Quotation from NSString

I have NSString's in the form of Johnny likes "eating" apples. I want to remove the quotations from my strings so that. Johnny likes "eating" apples becomes John likes apples I've been playing with NSScanner to do the trick but I'm getting some…
Ternary
  • 2,401
  • 3
  • 31
  • 54
1
vote
2 answers

NSScanner never reaches "isAtEnd" or don't scann full string

I've got an issue making scanner working for this particular string. here comes the code : tempString = @"30.15 in. Hg (1021 hPa)"; scanner = [NSScanner scannerWithString:tempString]; //setting the scanning location, [scanner…
Vassily
  • 899
  • 2
  • 8
  • 19
1
vote
1 answer

NSScanner simple question on iphone

my string is k= /Users/applefan/Library/Application Support/iPhone Simulator/3.1.3/Applications/422B3239-F521-4985-89FE-EC778C57C0AB/Documents/1.sql now how to get 1 from 1.sql i did somethins like this NSScanner *scanner = [NSScanner…
prajakta
  • 673
  • 6
  • 26
1
vote
2 answers

Convert "1.0E-4" from NSString to double

I want to get the double value from "1.04E-4" NSString, but I didn't manage yet how to do it. I tried the following: 1. NSString* str = @"1.0E-4"; double value = [str doubleValue]; //returns 0.0001 2. NSString* str = @"1.0E-4"; double…
Alexandru Circus
  • 5,478
  • 7
  • 52
  • 89
1
vote
2 answers

NSScanner vs. componentsSeparatedByString

I have a large text file (about 10 MB). In the text file there are values like (without the empty lines between the rows, I couldn't format it here…
Mikael
  • 3,572
  • 1
  • 30
  • 43
1
vote
2 answers

How to get a part of a NSString

"http://stackoverflow.com/pqr?name=XYZ&age=26" for example in the above string i need the value of name that is XYZ. how to get that..? Thanks
rockey
  • 638
  • 4
  • 16
  • 34
1
vote
1 answer

Confusion regarding NSScanner (Scanner)

I wrote an extension to return a UIColor from a hexadecimal string. Although it works, I don't quite understand the purpose of this piece of code var rgbValue: UInt32 = 0 Scanner(string: cleanHexStr).scanHexInt32(&rgbValue) Could you provide some…
Tarang Hirani
  • 560
  • 1
  • 12
  • 43
1
vote
1 answer

Getting Wikipedia Article Summary using NSScanner Problem

I am trying to get the summary of an article and download it as a string. This works great with some articles, but the wikipedia website is inconsistent. So NSScanner fails pretty often while it works fine for other articles. Here's my NSScanner…
Pripyat
  • 2,937
  • 2
  • 35
  • 69
1
vote
1 answer

String upto first non white space character in objective c

I have a string like NSString * aString = @"\n \n \n This is my string "; I need to extract firs blank spaces and new line characters upto first non-whitespace non-newline character. that is the output should be NSString *output = @"\n …
Johnykutty
  • 12,091
  • 13
  • 59
  • 100
1
vote
1 answer

8 bit hex string to signed integer

I have an 8 bit Hex Value like: "FB" (-5). Now I need an signed integer value for this hex. The NSScanner don't work on this place, because you need an 4 Byte hex value, to get it negative. Before I start some bit manipulation, maybe someone of you…
Watsche
  • 438
  • 2
  • 13
1
vote
3 answers

Objective-C: Convert Hex Strings to Integers to Compare Which is Greater

My goal is to compare two hex strings and determine which number is higher. I assume I need to convert those hex strings to integers to be able to compare them mathematically, but the conversion to unsigned isn't working. Here's what I've…
Clifton Labrum
  • 13,053
  • 9
  • 65
  • 128
1
vote
2 answers

NSScanner based on last occurrence of substring "@"

I have a user name system similar to twitters using the @ symbol. I have it set up to message users by typing @username. This is basically identical to mentions in Twitter. So far I have been able to detect the text following the @ symbol and to…
Kyle Begeman
  • 7,169
  • 9
  • 40
  • 58
1
vote
1 answer

iOS NSScanner selecting a certain string out of 2 different inputs

I have the following style string passed in:

and

Paulius Dragunas
  • 1,702
  • 3
  • 19
  • 29
1
vote
1 answer

Porting the Javascript replace() function to Objective C

Im trying to port over some Javascript code into Objective C, and I'm wondering what is the best approach for the Javascript .replace() function. My javascript looks like this: str = str.replace(/(\r\n|\r|\n)/g,'_r'); How would I achieve this with…
Jimmery
  • 9,783
  • 25
  • 83
  • 157