nsscanner

NSScanner vs. componentsSeparatedByString

匆匆过客 提交于 2019-12-11 13:25:04
问题 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 properly): ;string1;stringValue1; ;string2;stringValue2; ;string3;stringValue3; ;string4;stringValue4; I'm parsing all the 'stringX' values to an Array and the 'stringValueX' to another string, using a pretty ugly solution: words = [rawText componentsSeparatedByString:@";"]; NSEnumerator *word = [words objectEnumerator]; while(tmpWord = [word

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

天大地大妈咪最大 提交于 2019-12-10 23:27:45
问题 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: string.index(string.startIndex, offsetBy: scanLocation)) } This code crashes when string contains multibyte characters. It turned out that scanLocation returns number of utf16 units, not number of characters parsed. How to convert scanLocation (code units) into character index?

IOS How to find full rss feed link with nsscanner class

半世苍凉 提交于 2019-12-10 18:29:10
问题 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. <link rel="alternate" type="application/rss+xml" title="RSS Feed" href="http://feeds.abcnews.com/abcnews/topstories" /> so, I have to use nsscanner class to find the link of RSS feed from HTML source. but i don't know proper pattern and which i have to set scanUpToString: and haracterSetWithCharactersInString: or etc. So, please help me how

Handling CGFloat with an NSScanner on arm64

孤者浪人 提交于 2019-12-10 14:55:50
问题 Apparently CGFloat is double on arm64: #if defined(__LP64__) && __LP64__ # define CGFLOAT_TYPE double # define CGFLOAT_IS_DOUBLE 1 # define CGFLOAT_MIN DBL_MIN # define CGFLOAT_MAX DBL_MAX #else # define CGFLOAT_TYPE float # define CGFLOAT_IS_DOUBLE 0 # define CGFLOAT_MIN FLT_MIN # define CGFLOAT_MAX FLT_MAX #endif So the code NSScanner *scanner = [NSScanner scannerWithString:string]; CGFloat c[components]; [scanner scanFloat:&c[i]] which was working fine for 32-bit apps, is broken for 64-bit

Optimize String Parsing

我是研究僧i 提交于 2019-12-10 03:21:24
问题 I have a requirement to parse data files in "txf" format. The files may contain more than 1000 entries. Since the format is well defined like JSON, I wanted to make a generic parser like JSON, which can serialise and deserialise txf files. On contrary to JSON, the mark up doesn't have a way to identify an object or an array. If an entry with same tag occurs, we need to consider it as an array. # Marks the start of an object. $ Marks the members of an object / Marks the end of an object

Optimize String Parsing

余生长醉 提交于 2019-12-05 02:02:35
I have a requirement to parse data files in "txf" format. The files may contain more than 1000 entries. Since the format is well defined like JSON, I wanted to make a generic parser like JSON, which can serialise and deserialise txf files. On contrary to JSON, the mark up doesn't have a way to identify an object or an array. If an entry with same tag occurs, we need to consider it as an array. # Marks the start of an object. $ Marks the members of an object / Marks the end of an object Following is a sample "txf" file #Employees $LastUpdated=2015-02-01 14:01:00 #Employee $Id=1 $Name=Employee

Using NSScanner to parse a string

廉价感情. 提交于 2019-12-04 22:35:31
问题 I have a string with formatting tags in it, such as There are {adults} adults, and {children} children . I have a dictionary which has "adults" and "children" as keys, and I need to look up the value and replace the macros with that value. This is fully dynamic; the keys could be anything (so I can't hardcode a stringByReplacingString ). In the past, I've done similar things before just by looping through a mutable string, and searching for the characters; removing what I've already searched

How to use NSScanner to parse .ics file

谁都会走 提交于 2019-12-04 13:52:09
问题 Could someone please show how i could parse a ics file using NSScanner? (Iphone App) e.g: if the .ics file was at this URL http://www.ibz.com/data/12345.ics (not a real URL!!!) How would i firstly save the .ics file into my iphone app and then secondly how would i parse the .ics file using NSScanner?? Please provide code examples.. 回答1: Code examples to do this completely and well would be quite extensive, and SO isn't the place for large sample applications. With that in mind, the general

Strange behaviour of NSScanner on simple whitespace removal

a 夏天 提交于 2019-12-04 01:34:49
I'm trying to replace all multiple whitespace in some text with a single space. This should be a very simple task, however for some reason it's returning a different result than expected. I've read the docs on the NSScanner and it seems like it's not working properly! NSScanner *scanner = [[NSScanner alloc] initWithString:@"This is a test of NSScanner !"]; NSMutableString *result = [[NSMutableString alloc] init]; NSString *temp; NSCharacterSet *whitespace = [NSCharacterSet whitespaceCharacterSet]; while (![scanner isAtEnd]) { // Scan upto and stop before any whitespace [scanner

What causes “NSScanner: nil string argument”?

你。 提交于 2019-12-03 22:11:07
I got this message when I save data to core data. NSScanner: nil string argument I didn't use any NSScanner method. Where did it come from? This is a bug? What should I do with it? Thanks help, please. Jeremy W. Sherman From experience, I can say that -[NSDecimalNumber initWithString:] with a nil string is one thing that causes that log message. Set a breakpoint on -[NSScanner initWithString:] to start with; if you don't catch it that way, then break on the other ways you might create a scanner, like +scannerWithString: . That's how I flushed my unwanted log statement out. FWIW, I had this