nsstring

How to prepare an NSURL from an NSString continaing international characters?

会有一股神秘感。 提交于 2019-11-28 12:37:43
I have to access a web server using a GET with international characters (Hebrew in my case but could be anything). So I make an NSString just fine but [NSURL URLWithString:urlString]; // returns nil. I realize I probably have to convert the international characters to percent codes. Is there a built in method in Objective-c to do so? Yes there is, you need -stringByAddingPercentEscapesUsingEncoding: method: [NSURL URLWithString:[string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; This would ensure NSURL *url does not return nil because of the "|" in the urlString .

Name for %@ %d in an NSString

纵然是瞬间 提交于 2019-11-28 12:37:18
What are these called in Objective C? @"%@" @"%d" @"%i" They are called format specifiers, could also be called 'placeholders in a string for the variables that will follow'. https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html They are NSString literal s. More specifically, they look they are being used as formatting strings for printf style functions. I believe that they are called 'format placeholders', as suggested by this wikipedia article: http://en.wikipedia.org/wiki/Printf_format_string#Format_placeholders 来源: https:/

NSString intValue not working for retrieving phone number

自闭症网瘾萝莉.ら 提交于 2019-11-28 12:26:11
问题 I have a phone number formatted as an easy to read phone number, i.e., (123) 123-4567 However, when I want to use that phone number in code, I need to parse that string into a number variable (such as an int ) However, [string intValue]; doesn't work - I've used intValue about a million times in previous projects, all with no problem, however here, every string I pass in, I get the same, random int back out: - (int)processPhoneNumber:(NSString *)phoneNumber { NSMutableString *strippedString =

ARC forbids autorelease?

为君一笑 提交于 2019-11-28 12:25:40
问题 New to ios and trying to return an NSString from an function. As I understand, I need to [NSString... alloc] init] in order to create the string for return. Also, since I called alloc , I guess I have to autorelease the object myself however I'm getting the message "ARC forbids explicit message send of 'autorelease'" so.. how do I tell ios when I'm done with that allocated NSString? - (NSString *) generateUID { char foo[32]; // create buffer of all capital psuedo-random letters for (int i = 0

NSString to Emoji Unicode

冷暖自知 提交于 2019-11-28 11:45:10
I am trying to pull an JSON file from the backend containing unicodes for emoji. These are not the legacy unicodes (example: \ue415), but rather unicodes that work cross platform (example: \U0001F604). Here is a sample piece of the json getting pulled: [ { "unicode": "U0001F601", "meaning": "Argh!" }, { "unicode": "U0001F602", "meaning": "Laughing so hard" } ] I am having difficulty converting these strings into unicodes that will display as emoji within the app. Any help is greatly appreciated! In order to convert these unicode characters into NSString you will need to get bytes of those

Escape Quotes in Objective-C

十年热恋 提交于 2019-11-28 11:15:06
I'm using this code snippet to encode characters to be friendly with a POST request: NSString *unescaped = [textField text]; NSString *escapedString = (__bridge_transfer NSString *)CFURLCreateStringByAddingPercentEscapes( NULL, (__bridge_retained CFStringRef)unescaped, NULL, (CFStringRef)@"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8); Which works great, but does not add escape Quotation marks: " How do I escape Quotation marks in IOS? I think I didn't word the question correctly. I needed to take the user inputted NSString from [textField text] and make sure that if there are quotation marks

Sort characters in NSString into alphabetical order

萝らか妹 提交于 2019-11-28 11:14:45
I'm trying to re-arrange words into alphabetical order. For example, tomato would become amoott, or stack would become ackst. I've found some methods to do this in C with char arrays, but I'm having issues getting that to work within the confines of the NSString object. Is there an easier way to do it within the NSString object itself? sunkehappy I think separate the string to an array of string(each string in the array contains only one char from the original string). Then sort the array will be OK. This is not efficient but is enough when the string is not very long. I've tested the code.

NSString allocation and initializing

淺唱寂寞╮ 提交于 2019-11-28 11:02:53
What is the difference between: NSString *string1 = @"This is string 1."; and NSString *string2 = [[NSString alloc]initWithString:@"This is string 2.]; Why am I not allocating and initializing the first string, yet it still works? I thought I was supposed to allocate NSString since it is an object? In Cocoa Touch, -(IBAction) clicked: (id)sender{ NSString *titleOfButton = [sender titleForState:UIControlStateNormal]; NSString *newLabelText = [[NSString alloc]initWithFormat:@"%@", titleOfButton]; labelsText.text=newLabelText; [newLabelText release]; } Why do I not allocate and initialize for the

How to get all NSRange of a particular character in a NSString?

送分小仙女□ 提交于 2019-11-28 10:47:40
I have two NSStrings: orgText and searchLetter . I want to highlight every occurrences of the searchLetter in the orgText with a red color. How can I get the NSRange of all occurrences of the searchLetter ? for eg : suppose: orgText = "abcahaiapaoiuiapplma" searchLetter = "a". I want to hightlight all "a" occurrences in "abcahaiapaoiuiapplma" with red color. Thanks. I wrote this method for my project - SUITextView with highlight : - (NSMutableAttributedString*) setColor:(UIColor*)color word:(NSString*)word inText:(NSMutableAttributedString*)mutableAttributedString { NSUInteger count = 0,

NSDateFormatter wrong string after formatting

故事扮演 提交于 2019-11-28 10:30:45
问题 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