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
3
votes
3 answers

Parsing CSV: how can NSScanner recognize empty field (i.e. ,,)?

I am very new to Xcode and trying - as millions - to parse a CSV file. I have read many contributions and I am managing it but I have a problem when my NSScanner intercepts an empty field: "Field_A, Field_B,, Field_D". I guess it is because it…
Fabrizio Prosperi
  • 1,398
  • 4
  • 18
  • 32
3
votes
1 answer

How to parse .srt file if it contains multiple lines of subtitle text using Scanner in swift?

My .srt file content like follows: 1
00:00:00,000 --> 00:00:01,000
This is the first line:
and it has a secondary line,
it may have more lines 2
00:00:01,000 --> 00:00:02,000
This is the second line
it may have more…
Rama Mahapatra
  • 81
  • 1
  • 1
  • 7
3
votes
1 answer

Converting scanLocation from utf16 units to character index in NSScanner (Swift)

In Swift 3.0 (NS)Scanner, string property returns the string being parsed and scanLocation returns the current scan location. I'm trying to extract the parsed text: var parsedText: String { return string.substring(to:…
Zmey
  • 2,304
  • 1
  • 24
  • 40
3
votes
2 answers

IOS How to find full rss feed link with nsscanner class

I am working on fetching data from rss feed based project.From searching on google i found that generally RSS link found in this format in source of HTML.
Badal Shah
  • 7,541
  • 2
  • 30
  • 65
3
votes
1 answer

Objective C Using NSScanner to obtain from html

I am trying to create an iOS app simply to extract the section of a web page. I have the code working to connect to the URL and store the HTML in an NSString I have tried this, but I am just getting null strings for my result NSScanner*…
Harvey
  • 1,320
  • 3
  • 13
  • 33
2
votes
4 answers

NSScanner scanUpToString leaking while using ARC

To parse part of the querystring of an URL I use this method : NSScanner *scanner = [[NSScanner alloc] initWithString:query]; [scanner setCharactersToBeSkipped:[NSCharacterSet characterSetWithCharactersInString:@"&?"]]; NSString…
Thizzer
  • 16,153
  • 28
  • 98
  • 139
2
votes
1 answer

filter a String with NSScanner and removed white space after numeric character

I've been trying to filter a string with the following code: //the String with the original text NSString *unfilteredString = @"( A1 )"; //initialize a string that will hold the result NSMutableString *resultString = [NSMutableString…
Pedro Sousa
  • 847
  • 1
  • 8
  • 12
2
votes
1 answer

Find next match of a phrase with NSScanner

I am using the following code to find a certain line of code in my HTML file: NSURL *requestTimetableURL = [NSURL URLWithString:@"http://www.dhsb.org/index.phtml?d=201435"]; NSLog(@"Loaded Timetable"); NSError *error; NSString *page = [NSString…
pixelbitlabs
  • 1,934
  • 6
  • 36
  • 65
2
votes
1 answer

iphone nscanner issue

It seems nsscanner cant do her job, when it scans a dynamically inputting string. Let me first write my codes: NSString *setext = mySearchBar.text; NSScanner *scanner = [NSScanner scannerWithString:setext]; NSString *a = @"a"; NSString…
wagashi
  • 894
  • 3
  • 15
  • 39
2
votes
2 answers

NSScanner Loop Question

I have an NSScanner object that scans through HTML documents for paragraph tags. It seems like the scanner stops at the first result it finds, but I need all the results in an array. How can my code be improved to go through an entire document? -…
Pripyat
  • 2,937
  • 2
  • 35
  • 69
2
votes
3 answers

How to split a string?

I have a string made of three strings like this NSString *first = ..; NSString *second = ..; NSString *third = ..; NSString joinedString; joinedString = [NSString stringWithFormat:@"%@ - %@ (%@)", first, second, third]; Now I need to get back the…
Lorenzo
  • 133
  • 1
  • 2
  • 6
2
votes
1 answer

Nested NSScanner Efficiency

Is running a nested NSScanner the most efficient method for parsing out a string of repeating elements or can the scanning be done in one pass? I have a string which is returned from a command line call (NSTAsk) to Apple's Compressor (there are no…
Hooligancat
  • 3,588
  • 1
  • 37
  • 55
2
votes
1 answer

Line number-aware scanning with NSScanner

I am creating a very simple parser for a small scripting system of my project, and I'm reading tokens using NSScanner. I need to be aware of line number of each token, so in case of a syntax error, I can display the line number. Here is my current…
Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389
2
votes
1 answer

How to parse HTML to PlainText while maintaining paragraph formatting

I have an iOS app that is pulling data from a Restful web service. A portion of the content I am receiving is being loaded into a UITextView. The portion that will be going into the text view is coming in as HTML format. I need to convert it from…
Ben
  • 967
  • 3
  • 9
  • 23
2
votes
1 answer

Ownership of NSString returned by reference from NSScanner

Is the 'reference returned' NSString from the methods: scanString:intoString: scanCharactersFromSet:intoString: scanUpToString:intoString: scanUpToCharactersFromSet:intoString: in the NSScanner class owned by the calling instance (retain count of…
Atlas
  • 236
  • 1
  • 11
1
2
3
9 10