nsscanner

NSTextView enclosing scroll view jumps on spacebar

为君一笑 提交于 2020-01-06 14:01:19
问题 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 via text view delegate methods. However, each time I enter a space, the enclosing scroll view scrolls back to the top of the text view. Can anyone give me a hint where this comes from ? 回答1: Probably not much hassle for those more experienced than

Find next match of a phrase with NSScanner

夙愿已清 提交于 2019-12-30 11:09:05
问题 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 stringWithContentsOfURL:requestTimetableURL encoding:NSASCIIStringEncoding error:&error]; [webView loadHTMLString:page baseURL:requestTimetableURL]; NSString* Period1; NSScanner *htmlScanner = [NSScanner scannerWithString:page]; [htmlScanner

Using NScanner to parse CSV File to Dictionary Array [duplicate]

帅比萌擦擦* 提交于 2019-12-25 19:03:47
问题 This question already has answers here : Create a Custom Formatted Dictionary Array from CSV File of Data (3 answers) Closed 6 years ago . I've created an iPhone app that has a dictionary array of locations (lat,long,point). I created the array by manually entering each value. myLocationArray = @[ @{ kStation : @"1", kLatitude : @( 41.656467), kLongitude : @(-81.277963) }, @{ kStation : @"2", kLatitude : @(41.657118), kLongitude : @(-81.276545) }, @{ kStation : @"3", kLatitude : @(41.658493),

determine if a string is a number with NSScanner

夙愿已清 提交于 2019-12-24 08:48:14
问题 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 how to make it work? - (BOOL)textFieldShouldReturn:(UITextField *)textField { NSScanner *scan = [NSScanner scannerWithString:[textField text]]; if ([scan scanFloat:NULL]){ [password resignFirstResponder]; [passwordLength resignFirstResponder];

What causes “NSScanner: nil string argument”?

三世轮回 提交于 2019-12-21 06:48:18
问题 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. 回答1: 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

Extracting price from string

谁说我不能喝 提交于 2019-12-13 21:10:04
问题 I am looking for a short and convenient way to extract a product's price from NSString. I have tried regular expressions, but always found some cases where did not match. The price can be any number including decimals, 0 and -1 (valid prices: 10, 10.99, -1, 0). NSString can contain a string like: @"Prod. price: $10.99" Thanks! 回答1: This will match all the examples you have given -?\d+(\.\d{2})? Optionally a - , followed by 1-many digits, optionally followed by a decimal point and 2 more

NSScanner Loop Question

我只是一个虾纸丫 提交于 2019-12-12 19:02:14
问题 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? - (NSArray *)getParagraphs:(NSString *) html { NSScanner *theScanner; NSString *text = nil; theScanner = [NSScanner scannerWithString: html]; NSMutableArray*paragraphs = [[NSMutableArray alloc] init]; // find start of tag [theScanner scanUpToString: @"

NSScanner working on WiFi but not 3G

柔情痞子 提交于 2019-12-12 01:06:50
问题 I have set up an NSScanner to work on the tap of a UIButton with the following code: -(IBAction)doLoadTTData { NSString *Period1String = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource: @"Period1String" ofType: @"txt"] usedEncoding:nil error:nil]; NSString *Period2String = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource: @"Period2String" ofType: @"txt"] usedEncoding:nil error:nil]; NSString *Period3String = [NSString stringWithContentsOfFile

iOS How to get all words coordinates in PDF page

随声附和 提交于 2019-12-11 20:59:18
问题 I have looked through many tutorials and usually stack users trow links to the pdfkitten, but as I've tested it I have not satisfied with result. So the search does not work with multiply word and etc. So what I am looking for I need to get all words from the pdf page and highlight it if the words cross some rectangle. 回答1: I used PDFKitten for the same. What I did was while scanning the PDF - Identify the words separated by spaces. Save the RenderingState(Model in PDFKitten code)word is

Getting Wikipedia Article Summary using NSScanner Problem

时光怂恿深爱的人放手 提交于 2019-12-11 13:29:19
问题 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 implementation: NSString *separatorString = @"<table id=\"toc\" class=\"toc\">"; NSScanner *aScanner = nil; NSString *container = nil; NSString *muString = [NSString stringWithString:@"</table>"]; aScanner = [NSScanner scannerWithString:string];