nsstring

string replace phone number iOS swift

巧了我就是萌 提交于 2019-11-28 10:27:36
I import a phone-number from "Contacts" and save in NSString . this string contains white-space and I try to delete them using the method: numero = numero.stringByReplacingOccurrencesOfString(" ", withString: "") this method doesn't work. func sostituisci( stringa: NSString! ) -> NSString { var numero: NSString = "" NSLog(stringa) numero = ((stringa as String).stringByReplacingOccurrencesOfString(" ", withString: "") as NSString) NSLog(numero) return numero } the output unchanged log 2014-11-05 17:54:50.734 HappyRicarica[33438:3119446] (327) 124-3503 2014-11-05 17:54:50.737 HappyRicarica[33438

Format a date from a string

风流意气都作罢 提交于 2019-11-28 10:27:01
I'm trying to format a date from a string into another format. For example: 2012-05-29 23:55:52 into 29/05 *newline* 2010 . I just don't get the logics behind NSDate and NSDateFormatter, I think.. Any help will be appreciated. Thanks :) You will need to create an NSDateFormatter, and then set it's dateFormat to match the first date you have, eg: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; That will set your date formatter to recognise your date string. You can then obtain an NSDate object from this using NSDate *myDate

NSJSONSerialization serialization of a string containing forward slashes / and HTML is escaped incorrectly

北城余情 提交于 2019-11-28 10:05:32
I am trying to convert some simple HTML into a string value in a JSON object and I'm having trouble getting the string encoding to not escape the string in NSJSONSerialization. Example... I have a string which contains some basic HTML text: NSString *str = @"<html><body><p>Samples / Text</p></body></html>"; The desired outcome is JSON with HTML as the value: { "Title":"My Title", "Instructions":"<html><body><p>Samples / Text</p></body></html>" } I'm using the standard technique to convert an NSDictionary to a NSString containing JSON: NSMutableDictionary *dict = [NSMutableDictionary dictionary

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

╄→гoц情女王★ 提交于 2019-11-28 10:03:44
问题 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

Return a word-wrapped NSString from a longer NSString [duplicate]

柔情痞子 提交于 2019-11-28 10:00:57
Possible Duplicate: UITextView : get text with wrap info I have been scouting the NSString library and numerous libraries for a function that can take a long string like this : Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean

Why can't LLDB evaluate this expression?

丶灬走出姿态 提交于 2019-11-28 09:56:32
Neither one of these statements can be processed by LLDB... why is it unable to come up with the NSString result and print it out expr -o -- [NSString stringWithFormat:@"%@", @"Wow this doesnt work??"] po [NSString stringWithFormat:@"%@", @"Wow this doesnt work??"] It seems that the expression command in lldb can generally not evaluate functions with variable argument lists. It fails even with a simple C function: int foo(char *msg, ...) { return 17; } (lldb) expr foo("bar") (int) $2 = 17 (lldb) expr foo("bar", 2) error: no matching function for call to 'foo' note: candidate function not

Replace a character at a certain index in NSString

旧时模样 提交于 2019-11-28 09:46:36
I'm looking for a way to replace a character at a certain index of a NSString. For example: myString = @"******"; I want to replace the 3rd " * " with an "A", so that the string looks like this: myString = @"**A***"; How can I achieve this? Thanks in advance aViNaSh Try with this: NSString *str = @"*******"; str = [str stringByReplacingCharactersInRange:NSMakeRange(3, 1) withString:@"A"]; NSLog(@"%@",str); There are really two options; Since NSString is read-only, you need to call mutableCopy on the NSString to get an NSMutableString that can actually be changed, then call

iOS CFStringTransform and Đ

大憨熊 提交于 2019-11-28 09:43:21
问题 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. 回答1: I am not 100%

Objective-C: Best way to extract substring from NSString?

大兔子大兔子 提交于 2019-11-28 09:36:17
I have a space-separated string like @"abc xyz http://www.example.com aaa bbb ccc" . How can I extract the substring @"http://www.example.com" from it? I know this is a very late reply, but you can get the substring "http://www.abc.com" with the following code: [@"abc xyz http://www.abc.com aaa bbb ccc" substringWithRange:NSMakeRange(8, 18)] Of course, you can still use an NSString for that. Try this: [yourString substringToIndex:<#(NSUInteger)#>]; //or [yourString substringFromIndex:<#(NSUInteger)#>]; //or [yourString substringWithRange:<#(NSRange)#>]; Morion If all of your substrings are

What is the purpose of having both NSMutableString and NSString?

↘锁芯ラ 提交于 2019-11-28 09:29:35
Why does Objective C provide both class NSString and subclass NSMutableString rather than just provide NSMutableString? Isn't a NSString equivalent to "const NSMutableString"? In C++, you have only one string class, std::string, and if you want a constant you declare a const std:string. I'm interested in knowing why I shouldn't just use NSMutableString everywhere and never bother with NSString? There must be a reason, or the language designers wouldn't provide both. maybe it takes up less storage or something? The reason for both classes is the same reason that you sometimes use a std::string