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

Objective-c Line breaks every 23 characters without breaking words

I found this algorithm from this post Objective-c Line breaks every 10 characters (Keeping words in tact) the problem is that it never returns the last word it always discards it somehow. NSString *sourceStr = @"The Chocholate Experience in the Anna…
ioskaveen
  • 196
  • 1
  • 4
  • 14
0
votes
2 answers

NSScanner & Array Loops

I am trying to use NSScanner is an NSArray enumeration loop. This however fails: -[NSXMLElement length]: unrecognized selector sent to instance 0x280da30 No, I am not calling length anywhere. It seems like the value of found gets changed before…
Pripyat
  • 2,937
  • 2
  • 35
  • 69
0
votes
1 answer

JSON format sometimes not same, how to extract the info from the different JSON format?

I'm using this to get the auto suggestion from Youtube. http://suggestqueries.google.com/complete/search?hl=en&ds=yt&client=youtube&hjson=t&cp=1&q=Like&format=5&alt=json ["Tire",[["tired",0],["tired lyrics",0],["tired alan walker remix",0],["tired…
user6005637
0
votes
1 answer

NSScanner not importing data

I'm trying to load a default set of data from a csv file into my core data db. So initially i'm trying to read in a csv file and output it to the log before trying to add it to the core data database. This is the code i'm using; //Find import…
zio
  • 2,145
  • 4
  • 21
  • 25
0
votes
1 answer

NSScanner issue with finding numbers that begin with 0

I having an issue using NSScanner. I have this string: 195 058 042 yuiyui 123 and I'm trying to just return the integers. however, any number that contains a 0 before the space doesn't get scanned property. var note = "195 048 042 yuiyui 123" let…
Tony
  • 656
  • 8
  • 20
0
votes
1 answer

NSScanner scanDouble UnsafeMutablePointer

I'm using NSScanner to scan a string and extract a double from it. Here's my sandboxed code to try and solve the problem let string = "maxage=1234567890" let scanner2 = NSScanner(string: string) scanner2.scanUpToString("=", intoString:…
gngrwzrd
  • 5,902
  • 4
  • 43
  • 56
0
votes
1 answer

unicode general category z* in whitespaceAndNewlineCharacterSet

in nscharacterset class there is whitespaceAndNewlineCharacterSet method which returns few unicodes, i was wondering what is z*,i searched online but couldn't find any explanations. can anyone tell what does unicode category z* mean exactly??? …
n devaraj
  • 134
  • 9
0
votes
1 answer

Scanning a string line by line

I have an nsstring with 50 of lines i want to scan a particular string using nsscanner scanning each lines. Is it possible ? Can anyone help me? Thanks in advance......
dragon
  • 317
  • 4
  • 18
0
votes
1 answer

Swift NSScanner doesn't return start character

I'm scanning an SVG path string, and using NSScanner to try and break it up into it's components. When it runs though I get the components, but I'm not getting back the "type" For example: "m 186.14021,456.15955 3.19716,8.75681 c 1.78393" Should…
Chris
  • 2,739
  • 4
  • 29
  • 57
0
votes
0 answers

NSScanner string always nil (EXC_BAD_INSTRUCTION(code=EXC_i386_INVOP,subcode=0x0))

When using NSScanner, the following code: var s: String? var b: NSString? let scn = NSScanner(string: "andgostring") scn.scanUpToString("go", intoString: &b) b = NSString(string:"http") s = b // <--- Crashes here ...crashes with…
Alterecho
  • 665
  • 10
  • 25
0
votes
1 answer

Parse all strings between strings of a file in Swift

I want to build a localization application for my javascript (pebble.js) application. It should find all Strings between l._(" and ") or ') or ", or ',. So for example I have the the line console.log(l._("This is a Test") + l._('%@ times %@ equals…
David Gölzhäuser
  • 3,525
  • 8
  • 50
  • 98
0
votes
1 answer

How to parse JSON response from Rest API

I am working on an app that will parse data from a Rest API. As I haven't done this before, I was wondering if NSScanner or NSRange would work for this. Here is an example using NSScanner for such purposes. It's a small string so it doesn't take…
J.J.
  • 1,128
  • 2
  • 23
  • 62
0
votes
1 answer

stringByReplacingOccurrencesOfString not functioning correctly

I created a small app which will get html from website and turn that into string. Now I want to delete some text from that string but it is not deleting that text. Here is my code that I wrote. -(void)dk { NSString *myURLString =…
AJ Tech
  • 75
  • 9
0
votes
1 answer

Getting the second paragraph in html - iOS

I am making an app which will get text from a website I have got this code so far - (void)viewDidLoad { [super viewDidLoad]; NSURL *URL = [NSURL URLWithString:@"http://rss.cnn.com"]; NSData *data = [NSData dataWithContentsOfURL:URL]; …
0
votes
2 answers

Use NSScanner or NSRange for url to find NSSet objects

Basically I'm trying to find NSSet objects contained in a url for my webview. How would I use NSScanner or NSRange to do this? Below is what I'm working with. //External file links NSURL* externalURL = [request URL]; NSString…
ChrisOSX
  • 724
  • 2
  • 11
  • 28