nsstring

In Objective C, what's the best way to extract multiple substrings of text around multiple patterns?

你离开我真会死。 提交于 2019-11-29 18:07:21
For one NSString, I have N pattern strings. I'd like to extract substrings "around" the pattern matches. So, if i have "the quick brown fox jumped over the lazy dog" and my patterns are "brown" and "lazy" i would like to get "quick brown fox" and "the lazy dog." However, the substrings don't necessarily need to be delimited by whitespace. Another example would be if you had multiple paragraphs of text and wanted to find all instances of "red" and "blue" in the text, but you wanted to show the instances of "red" and "blue" in context, but by "context" you didn't care if the context started and

Converting string to int changes the value

我的未来我决定 提交于 2019-11-29 18:01:23
I'm trying to convert a string value I retrieved from an XML parser into an integer. Unfortunately, I'm finding that the integer value is not reflecting the number in the string, and I can't figure out why. Here is my code: int maxTweetID = [[[_dataArray lastObject]tweetID]intValue]; NSLog(@"String Value of tweet ID: %@",[[_dataArray lastObject]tweetID]); NSLog(@"Int Value of tweet ID: %i",[[[_dataArray lastObject]tweetID]intValue]); and here is what I'm getting from the debugger: 2012-05-15 10:58:44.395 nearYou[2460:707] String Value of tweet ID: 202425636143370242 2012-05-15 10:58:44.396

How to send an NSString to another view controller

让人想犯罪 __ 提交于 2019-11-29 17:33:34
I have an IBAction that when triggered calls another method in a different view controller ( APICallsViewController). I'm looking to also send that method an NSString (message) here's my IBAction with the push to the APICallsViewController and also the NSString message. My question might be how do I grab the contents of that NSString in the other view controller's method. thanks for any help -(IBAction) someMethod{ APICallsViewController *apiViewController = [[APICallsViewController alloc] init]; [self.navigationController pushViewController:apiViewController animated:YES]; NSString *message =

NSUrl from NSString returns null

拈花ヽ惹草 提交于 2019-11-29 17:25:40
I want to parse the location of my Documents Directory to NSUrl from NSString I have. when my console NSLog(stringURL) i get: "/var/mobile/Applications/2B35D06D-6E4A-40F2-833E-28463A946834/Library/Application Support/MyAppDirectory" as an output. but when I do NSURL* url = [NSURL URLWithString:stringUrl]; and NSLog(url) i get (null) as an output. WHat am I doing wrong here? From the apple documentation "An NSURL object initialized with URLString. If the URL string was malformed or nil, returns nil." Your stringURL isn't a correct formed url. For reference: https://developer.apple.com/library

Memory leak in NSString stringWithUTF8String: with ARC enabled

佐手、 提交于 2019-11-29 17:25:01
In my application i have enabled the ARC. But in my application following lines gives me memory leaks according to instruments. It is in ios 7.0. -(id)init{ variables = [[NSMutableArray alloc] init]; // Leak events = [[NSMutableArray alloc] init]; //Leak return self; } Update But in my app if i do something like below it does not show me any leak. But i can't add items in to the variables. -(id)init{ variables = [[[NSMutableArray alloc] init] copy]; // No Leak events = [[[NSMutableArray alloc] init] copy]; //No Leak return self; } -- NSString *utfString =[NSString stringWithUTF8String:(const

NSDateFormatter wrong string after formatting

给你一囗甜甜゛ 提交于 2019-11-29 17:02:11
I receive a date through a string parameter, which is tempDateString, in a [day month year] format (for ex. 01 05 2005): NSLog(@"tempdatestring %@", tempDateString); NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"dd MM YYYY"]; NSDate *dayDate = [dateFormatter dateFromString:tempDateString]; NSLog(@"daydate %@", dayDate); My problem is, that the two logs don't match. The outputs are: tempdatestring 04 10 2012 daydate 2011-12-24 22:00:00 +0000 What should I change at the date formatter's date format, to get the good date? 2 Problems your format is

iOS CFStringTransform and Đ

情到浓时终转凉″ 提交于 2019-11-29 16:15:44
I'm working on an iOS app in which I have to list and sort people names. I've some problem with special character. I need some clarification on Martin R answer on https://stackoverflow.com/a/15154823/2148377 You could use the CoreFoundation CFStringTransform function which does almost all transformations from your list. Only "đ" and "Đ" have to be handled separately: Why this particular letter? Where does this come from? Where can I find the documentation? Thanks a lot. I am not 100% sure, but I think it can be seen from the Unicode Data Base http://www.unicode.org/Public/6.2.0/ucd/UnicodeData

Calling NSString method on a String in Swift

非 Y 不嫁゛ 提交于 2019-11-29 16:01:09
问题 Apple's Swift documentation states that If you are working with the Foundation framework in Cocoa or Cocoa Touch, the entire NSString API is available to call on any String value you create If I have a String object eg var newString: String = "this is a string" How do I perform NSString operations like containsString on my String var? 回答1: After doing some research, it looks like containsString is not a String function, but can be accessed by bridging to an NSString . Under Apple's

calling [myString release] does NOT decrement [myString retainCount]

懵懂的女人 提交于 2019-11-29 15:54:01
I have the following situation, which seems to cause my iPad application to leak memory. I have a class with a string property... @property(nonatomic,retain) NSString * synopsis; I set the string property from some HTTP response, either from JSON or XML response. At that point the retain count of the synopsis object is 1. But I have this situation: I save the synopsis to a local sqlite database, and then I want to release it from memory, but I have the situation where strangely, calling [synopsis release] from within my object does not decrement the retain count to 0. (void) save { NSLog(@

Detecting if NSString contains chinese characters

烂漫一生 提交于 2019-11-29 15:45:56
I have an UISearchBar , and I want my data to be sorted by pinYin if the user inputs English, and sorted by the characters themselves when the user inputs Chinese characters. Is there something like if (searchText isKindofClass: UTF-8String) to detect if an NSString contains Chinese characters? You can use a NSRegularExpression to search for "character families" : https://developer.apple.com/library/mac/#documentation/Foundation/Reference/NSRegularExpression_Class/Reference/Reference.html http://userguide.icu-project.org/strings/regexp They give an example of \p{script=cyrillic} , I guess by