nsstring

NSString - Unicode to ASCII equivalent

杀马特。学长 韩版系。学妹 提交于 2019-11-27 20:09:10
I need to convert NSString in unicode to NSString in ASCII changing all local characters: Ą to A, Ś to S, Ó to O, ü to u, And so on... What is the simplest way to do it? -[NSString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES] . All of the examples you gave are handled as you want. Looks like characters with no obvious analog, such as ☃, go to '?'. NSString *unicode = @"Chào mừng đến với Việt Nam."; NSString *standard = [unicode stringByReplacingOccurrencesOfString:@"đ" withString:@"d"]; standard = [standard stringByReplacingOccurrencesOfString:@"Đ" withString:@"D"]; NSData

Case insensitive comparison NSString

强颜欢笑 提交于 2019-11-27 19:48:14
问题 Can anyone point me to any resources about case insensitive comparison in Objective C? It doesn't seem to have an equivalent method to str1.equalsIgnoreCase(str2) 回答1: if( [@"Some String" caseInsensitiveCompare:@"some string"] == NSOrderedSame ) { // strings are equal except for possibly case } The documentation is located at Search and Comparison Methods 回答2: NSString *stringA; NSString *stringB; if (stringA && [stringA caseInsensitiveCompare:stringB] == NSOrderedSame) { // match } Note:

Read a text file line by line in Swift?

不打扰是莪最后的温柔 提交于 2019-11-27 19:37:50
Just started learning Swift, I have got my code to read from the text file, and the App displays the content of the Entire Text file. How can I display line by line and call upon that line multiple times? TextFile.txt contains the following. Banana Apple pear strawberry blueberry blackcurrent the following is what currently have.. if let path = NSBundle.mainBundle().pathForResource("TextFile", ofType: "txt"){ var data = String(contentsOfFile:path, encoding: NSUTF8StringEncoding, error: nil) if let content = (data){ TextView.text = content } also if there is another way, of doing this please

how to check if NSString = a specific string value?

走远了吗. 提交于 2019-11-27 19:13:04
Hi I am woundering if you can check to see if a NSString equals a specific value say for instance a name of a person? I am thinking along the lines of if (mystring == @"Johns"){ //do some stuff in here } Vanya if ([mystring isEqualToString:@"Johns"]){ //do some stuff in here } Here is another method you might want to use in some circumstances: NSArray * validNames = @[ @"foo" , @"bar" , @"bob" ]; if ([validNames indexOfObject:myString].location != NSNotFound) { // The myString is one of the names in the valid names array } Or if you have a large amount of names in the array you could use a

Do I need to release a constant NSString?

為{幸葍}努か 提交于 2019-11-27 19:00:49
问题 I'm reading memory management rules to this point where it said - (void)printHello { NSString *string; string = [[NSString alloc] initWithString:@"Hello"]; NSLog(@"%@", string); [string release]; } you have ownership and have to release string , but I'm curious about the @"Hello" . @" " is the syntax for creating and NSString , and it's an object. So doesn't that get leaked? 回答1: @"…" is a literal instance of NSString . When the compiler sees a literal string, it maps the string into the

NSString containsString crashes

南楼画角 提交于 2019-11-27 18:39:26
I'm trying to filter an array according to one of it's string fields. Both nameLower and filterLower has NSString value inside, and yet i keep getting: __NSCFString containsString:]: unrecognized selector sent to instance 0x7f876b79e160 -(void) filterFriendsArray:(NSString*)filter { [_filteredFriendsArray removeAllObjects]; for (FacebookUser* user in _friendsArray) { NSString* nameLower = [user.user.name lowercaseString]; NSString* filterLower = [filter lowercaseString]; if ([nameLower containsString:filterLower]) [_filteredFriendsArray addObject:user]; } _displayedFriendsArray =

NSString: newline escape in plist

南笙酒味 提交于 2019-11-27 18:28:21
I'm writing a property list to be in the resources bundle of my application. An NSString object in the plist needs to have line-breaks in it. I tried \n , but that doesn't work. What do I do to have newlines in my string in the plist? Thanks. If you're editing the plist in Xcode's inbuild plist editor, you can press option-return to enter a line break within a string value. I found a simpler solution: NSString *newString = [oldString stringByReplacingOccurrencesOfString:@"\\n" withString:@"\n"]; It seems the string reader escapes all characters that need to be escaped such that the text from

When should I use NSURL instead of NSString and vice versa?

你离开我真会死。 提交于 2019-11-27 18:20:02
问题 This is not a question about a pertinent problem. It's a question by which I try to deepen my understanding of Objective-C or more specific Cocoa Foundation. When dealing with uploading and download files from a server to my apps, I'm constantly torn between using NSURL or NSString for all things path related. Of course when there's an existing API I just use it according to the specs. But when I store my own paths or create custom classes that deal with them, I'm confused which of the two

How to create a NSString from a format string like @“xxx=%@, yyy=%@” and a NSArray of objects?

五迷三道 提交于 2019-11-27 18:00:37
Is there any way to create a new NSString from a format string like @"xxx=%@, yyy=%@" and a NSArray of objects? In the NSSTring class there are many methods like: - (id)initWithFormat:(NSString *)format arguments:(va_list)argList - (id)initWithFormat:(NSString *)format locale:(id)locale arguments:(va_list)argList + (id)stringWithFormat:(NSString *)format, ... but non of them takes a NSArray as an argument, and I cannot find a way to create a va_list from a NSArray... Peter N Lewis It is actually not hard to create a va_list from an NSArray. See Matt Gallagher's excellent article on the subject

NSString by removing the initial zeros?

折月煮酒 提交于 2019-11-27 17:56:15
问题 How can I remove leading zeros from an NSString ? e.g. I have: NSString *myString; with values such as @"0002060" , @"00236" and @"21456" . I want to remove any leading zeros if they occur: e.g. Convert the previous to @"2060" , @"236" and @"21456" . Thanks. 回答1: For smaller numbers: NSString *str = @"000123"; NSString *clean = [NSString stringWithFormat:@"%d", [str intValue]]; For numbers exceeding int32 range: NSString *str = @"100004378121454"; NSString *clean = [NSString stringWithFormat: