nsstring

Problem using NSRange: Index out of bounds

你。 提交于 2020-01-03 19:33:21
问题 I am trying to detect website URL's in my string and then doing some attribution string stuff like bolding it etc. My regex is defined as: static NSRegularExpression *websiteRegularExpression; static inline NSRegularExpression * WebsiteRegularExpression() { if (!websiteRegularExpression) { websiteRegularExpression = [[NSRegularExpression alloc] initWithPattern:@"\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[A-Z0-9+&@#/%=~_|]" options:NSRegularExpressionCaseInsensitive error:nil]; } return

to trim spaces an \n from NSString

孤者浪人 提交于 2020-01-03 12:35:33
问题 I have NSString @" (\n "Bi_ss" \n) " I want to get String @"Bi_ss " Any one has any idea about this ? Thank you 回答1: NSString *trimmedString = [string stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]]; From Cocoanetics... 回答2: Take a look at the NSString method stringByReplacingOccurrencesOfString:withString for example, this should be able to perform the basic task you want it to do. 来源: https://stackoverflow.com/questions/9431026/to-trim-spaces-an-n-from

to trim spaces an \n from NSString

落花浮王杯 提交于 2020-01-03 12:35:21
问题 I have NSString @" (\n "Bi_ss" \n) " I want to get String @"Bi_ss " Any one has any idea about this ? Thank you 回答1: NSString *trimmedString = [string stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]]; From Cocoanetics... 回答2: Take a look at the NSString method stringByReplacingOccurrencesOfString:withString for example, this should be able to perform the basic task you want it to do. 来源: https://stackoverflow.com/questions/9431026/to-trim-spaces-an-n-from

What is the guaranteed lifecycle of -[NSString UTF8String]?

和自甴很熟 提交于 2020-01-03 12:33:06
问题 The docs vaguely say that it will stick around as long as needed, but when is it actually deallocated? When the original NSString is deallocated? When the current autorelease pool clears? Sometime else? Furthermore, when is it guaranteed to stay for, as opposed to the current implementation? If it stays for the lifetime of the NSString, will the same pointer be returned every time? Thanks 回答1: Update 30/11/2018 As David Dunham pointed out in comments, the Apple documentation has changed (the

What is the guaranteed lifecycle of -[NSString UTF8String]?

 ̄綄美尐妖づ 提交于 2020-01-03 12:33:05
问题 The docs vaguely say that it will stick around as long as needed, but when is it actually deallocated? When the original NSString is deallocated? When the current autorelease pool clears? Sometime else? Furthermore, when is it guaranteed to stay for, as opposed to the current implementation? If it stays for the lifetime of the NSString, will the same pointer be returned every time? Thanks 回答1: Update 30/11/2018 As David Dunham pointed out in comments, the Apple documentation has changed (the

What are the characters that stringByAddingPercentEscapesUsingEncoding escapes?

半城伤御伤魂 提交于 2020-01-03 09:04:11
问题 I've had to switch from stringByAddingPercentEscapesUsingEncoding to CFURLCreateStringByAddingPercentEscapes because it doesn't escape question marks (?). I'm curious what exactly it does escape, and the rationale behind the partial escaping vs RFC 3986. 回答1: Some good categories have been created for doing just what you need: http://iosdevelopertips.com/networking/a-better-url-encoding-method.html http://www.cocoanetics.com/2009/08/url-encoding/ The rationale for leaving certain characters

How to pad NSString with spaces?

◇◆丶佛笑我妖孽 提交于 2020-01-03 07:17:21
问题 For example, I need the NSString have at least 8 chars....instead of using a loop to add the left pad spaces on this, is there anyway to do it? Examples: Input: |Output: Hello | Hello Bye | Bye Very Long |Very Long abc | abc 回答1: Here is an example of how you can do it: int main (int argc, const char * argv[]) { NSString *str = @"Hello"; int add = 8-[str length]; if (add > 0) { NSString *pad = [[NSString string] stringByPaddingToLength:add withString:@" " startingAtIndex:0]; str = [pad

将字典写入属性列表文件中

我与影子孤独终老i 提交于 2020-01-03 05:58:08
1 NSMutableDictionary *dict = [NSMutableDictionary dictionary]; 2 [dict setObject:@"mj" forKey:@"name"]; 3 [dict setObject:[NSNumber numberWithInt:10] forKey:@"age"]; 4 5 // 获取应用沙盒的根路径 6 NSString *home = NSHomeDirectory(); 7 NSString *documents = [home stringByAppendingPathComponent:@"Documents"]; 8 // 属性列表的默认拓展名是plist 9 NSString *path = [documents stringByAppendingPathComponent:@"dict.plist"]; 10 11 [dict writeToFile:path atomically:YES]; 来源: https://www.cnblogs.com/wangshengl9263/p/3265964.html

How to convert NSData of Image from database to NSString in iPhone?

﹥>﹥吖頭↗ 提交于 2020-01-03 05:06:11
问题 I am converting NSData of Image from database to NSString in iPhone Here is my code imageData1 = [[NSData alloc] initWithBytes:sqlite3_column_blob(compiledStatement, 2) length: sqlite3_column_bytes(compiledStatement, 2)]; NSLog(@"the data length %d",[imageData1 length]); NSString* newStr1 = [[NSString alloc] initWithData:imageData1 encoding:NSUTF8StringEncoding]; The length of data is 6511 , but the newstr1 is nil With reference to this stack overflow question. I can't create a UTF-8 encoded

problem with NSString, it's losing it's value after assigning it to a function parameter

余生长醉 提交于 2020-01-03 04:52:10
问题 Objective-C is really wierd, i can't get the hang of it... I have a NSstring that is losing it's value if I try to reassign it... Here's how I use it.. Can anyone tell me what am I doing wrong? it's happening at the assigning of the new value.. @interface PageViewController : UIViewController { NSString *mystring; } - (void)viewDidLoad { mystring=[ [NSString alloc] initWithString:@""]; } -(void) function_definition:(NSString *) param { ............. mystring=param; ......... } 回答1: Most