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

Parsing Multiple Date Formats

Possible Duplicate: Converting mutliple date format into a single format in iPhone I am trying to parse an RSS and extract an NSString for dates from the content section of the RSS, and convert it to an NSDate. Here is what I have so far: The…
user717452
  • 33
  • 14
  • 73
  • 149
2
votes
2 answers

iPhone SDK:NSScanner crashing randomly

I have an application that scans text from a website in order to get the information and put it into my application. So in this case I'm retrieveing the number of notifications that the user has on facebook. Everything works fine except that the…
mrprogrammer
  • 87
  • 2
  • 10
1
vote
2 answers

Faster way to grab images from XML feed

I'm pulling data into a UITableView via an XML feed from a Wordpress site. I wanted to display the table with an image if the post contained one and a default image if it did not. So in my - (void) parser:(NSXMLParser *)parser…
Sonny Parlin
  • 931
  • 2
  • 13
  • 28
1
vote
2 answers

Use RegEx or NSScanner in Obj-C to convert newline characters to html bullets

My app accesses a poor web service that returns output like this: Title\n\nInfo1\nInfo2\nInfo3\n ... To clarify, the text is not literally ..., and the info is not literally numbered, I just wanted to show that they are distinct. I want to display…
tacos_tacos_tacos
  • 10,277
  • 11
  • 73
  • 126
1
vote
1 answer

NSScanner behavior

I am very new to iOS development. I am trying to parse a simple csv file that has about 10 lines separated by commas. I am using the code below but not able understand why NSScanner, when parsing the fields (fields in the code below) does not go to…
RXP
  • 517
  • 4
  • 18
1
vote
1 answer

Find number nodes in NSString and add underscore before it to fix invalid XML

I have an XML string that gets returned to me, sometimes it is invalid using numbers as node names such as: <2>. I would like to scan my entire NSString which holds the XML, and search for the following:
Nic Hubbard
  • 41,587
  • 63
  • 251
  • 412
1
vote
1 answer

Parsing free format text in Cocoa

My Cocoa app needs to parse free format text entered via NSTextView. The result of the process should be a collection of keyword strings which can then be displayed for review to the user and optionally persisted using Core Data. I looked at…
Roger
  • 4,737
  • 4
  • 43
  • 68
1
vote
2 answers

determine if a string is a number with NSScanner

i'm trying to find out if my string contains any floatValue, and resign the first responder if it's the case, if it's not, the textfield keyboard should stay on screen. This code always hides the keyboard, even if it's not a floatValue : do you know…
Paul
  • 6,108
  • 14
  • 72
  • 128
1
vote
1 answer

Get substring from xml string objective-c

I know this question has been asked many times. I've response string that contains xml. 116363111 For each request i receive new short xml string, and i need to get value in "response"…
Timur Mustafaev
  • 4,869
  • 9
  • 63
  • 109
1
vote
3 answers

Find characters from the given string with numbers.

How do I get string using NSScanner from a string which contains string as well as numbers too? i.e. 001234852ACDSB The result should be 001234852 and ACDSB I am able to get numbers from the string using NSScanner and characters by using…
alloc_iNit
  • 5,173
  • 2
  • 26
  • 54
1
vote
1 answer

use NSScanner to parse string

The two-line string to parse is: 00:02.0 VGA compatible controller [0300]: Intel Corporation 82945G/GZ Integrated Graphics Controller [8086:2772] (rev 02) 00:02.1 Display controller [0380]: Intel Corporation 82945G/GZ Integrated Graphics…
yolo
  • 2,757
  • 6
  • 36
  • 65
1
vote
2 answers

NSTextView enclosing scroll view jumps on spacebar

I have an odd behavior with my app and I don't know where it comes from. I have implemented a NSScanner for a text view content that works very well. The scanner works in conjunction with the text storage to set attributes on the text storage string…
Tom
  • 145
  • 1
  • 8
1
vote
1 answer

Why am I receiving an error message when attempting NSScanner to use in a NSString statement?

I would like to know why I get an error message Thread 1: Program received signal: "SIGABRT") When I use this line of code: NSScanner *userEntered = [[NSScanner alloc] scannerWithString:temp]; The error is: 2011-04-18 02:06:11.995 XXX[25929:207]…
1
vote
4 answers

iOS custom file format loading with NSData & NSCoding

I'm looking for some guidance from some iOS Cocoa programmers as to how one might implement a mechanism to load and parse a custom file format into the model objects that I'll be using in memory. I know there must be many ways to crack this nut,…
pohl
  • 3,158
  • 1
  • 30
  • 48
1
vote
2 answers

NSScanner to parse file

I am trying to use NSScanner to parse an ics file (that for the sake of parsing has been converted to a text file) i.e: calendar file.txt here is the format of the text file: BEGIN:VEVENT DTSTAMP:20101129T061152Z UID:101139897313172011030314:00 …
Ibz
  • 518
  • 1
  • 8
  • 26
1 2
3
9 10