nsstring

Convert NSString to NSDate [duplicate]

廉价感情. 提交于 2019-11-30 22:43:06
Possible Duplicate: Converting NSString to NSDate (and back again) I make a request to the flickr api and it returns me the date in the following format "2013-02-01T06:25:47Z" How do i convert this into NSDate format?? Madhu It's a simple one, converting NSString to NSDate we use NSDateformatter using dateFromString method. We need to provide the Dateformatter style with existing style for NSString NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"]; NSDate *date = [dateFormatter dateFromString:@"2013-02-01T06:25:47Z"];

Include a variable inside a NSString?

允我心安 提交于 2019-11-30 22:19:19
This works fine, we all know that: NSString *textoutput = @"Hello"; outLabel.text = textoutput; However, what if you want to include a variable inside that NSString statement like the following: NSString *textoutput =@"Hello" Variable; In C++ I know when I cout something and I wanted to include a variable all I did was soemthing like this: cout << "Hello" << variableName << endl; So I'm trying to accomplish that with Objective-C but I don't see how. You can do some fancy formatting using the following function: NSString *textoutput = [NSString stringWithFormat:@"Hello %@", variable]; Note that

How to copy a wchar_t into an NSString?

谁说胖子不能爱 提交于 2019-11-30 20:30:59
问题 I'm using stringWithFormat @"%ls" to do it and I only see the first character copied, which makes me think it's still assuming it's a single byte char. Any ideas? 回答1: Use initWithBytes:length:encoding . You will have to know the encoding that wchar_t uses, I believe it is UTF-32 on Apple platforms. #if defined(__BIG_ENDIAN__) # define WCHAR_ENCODING NSUTF32BigEndianStringEncoding #elif defined(__LITTLE_ENDIAN__) # define WCHAR_ENCODING NSUTF32LittleEndianStringEncoding #endif [[NSString

Difference between these two NSString methods

时间秒杀一切 提交于 2019-11-30 19:47:31
So I just got asked this at an interview today and after some googling am still unable to figure out the answer (in fact I couldn't even find any code at all which used the [NSString string] method). What is the difference between NSString *someString = [NSString string]; NSString *someString = [[NSString alloc] init]; Now my initial thoughts were that [NSString string] would return an object which would be autoreleased whereas using alloc and init would return an object which has been retained. However it seems that this answer was incorrect. I've looked at the NSString class reference in the

NSString encoding special characters like !@#$%^&

℡╲_俬逩灬. 提交于 2019-11-30 19:31:48
问题 How can i encode my NSString so all the special character for example & becomes &amp and ' becomes &apos? I am not sure if encoding is the right word for it so please correct me if I am wrong. Thanks 回答1: What you are talking about is called HTML Entities. There exists a category claiming to solve this: NSString+HTML. For URL Escaping (while we're at it) use this: @nterface NSString (Escaping) - (NSString *)percentEscapedString - (NSString *)percentUnescapedString @end @implementation

NSString @“\\” adding backslash character objective-c

↘锁芯ラ 提交于 2019-11-30 19:20:23
Does anyone know of an easy way to add a single backslash ( \ ) to a NSString in Objective-C? I am trying to have a NSString *temp = @"\/Date(100034234)\/" ; I am able to get a double backslash or no backslash, but unable to get a single backslash. Any help would be appreciated. Thanks The string @"\\" is a single backslash, @"\\\\" is a double backslash gerry3 The strings and NSLog are working fine for me (iPhone SDK 3.1.2 and Xcode 3.2.1): NSLog(@"\\"); // output is one backslash NSLog(@"\\\\"); // output is two backslashes NSLog(@"\\/Date(100034234)\\/"); // output is \/Date(100034234)\/

iPhone SDK NSString To NSDate

混江龙づ霸主 提交于 2019-11-30 19:03:59
I got a string from parsing a XML file which looks like this: Fri, 09 Apr 2010 00:00:45 +0200 and the corresponding pattern should be this "EEE, dd MMM yyyy HH:mm:ss ZZ", but I get (null). This is my code: NSString *dateString = @"Fri, 09 Apr 2010 00:00:45 +0200"; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss ZZ"]; NSDate *date = [dateFormatter dateFromString:dateString]; NSLog(@"date:%@",date); // result date:(null) Edit: This works for me now, I had to switch to en-US locale: NSLocale* usLocale = [[NSLocale alloc]

URL-encoding and HTML-encoding NSStrings

妖精的绣舞 提交于 2019-11-30 19:03:08
Is their a method to encode/decode HTML and URL (in Xcode, using Objective-C)? [NSString stringWithContentsOfFile:<#(NSString *)path#> encoding:<#(NSStringEncoding)enc#> error:<#(NSError **)error#>] This doesn't seem to work how i expected. I thought it will convert special characters like "<" to equivalent HTML entities i.e. "<" in this case. Here's a reference to the w3school link related to this topic (general): HTML URL Encoding Reference HTML Entities Reference Thanking in anticipation. Returns a representation of the receiver using a given encoding to determine the percent escapes

Swift string count() vs NSString .length not equal

人走茶凉 提交于 2019-11-30 18:57:18
Why do these two lines give me different results? var str = "Hello 😘" // the square is an emoji count(str) // returns 7 (str as NSString).length // returns 8 Original for reference: This is because Swift uses Extended Grapheme Clusters. Swift sees the smiley as one character, but the NSString method sees it as two Unicode Characters, although they are "combined" and represent a single symbol. I think the documentation says it best: The character count returned by the count(_:) function is not always the same as the length property of an NSString that contains the same characters. The length of

ios UrlEncode与UrlDecode

此生再无相见时 提交于 2019-11-30 18:46:41
url字符串中具有特殊功能的特殊字符的字符串,或者中文字符,作为参数用GET方式传递时,需要用urlencode处理一下。当然,有时作为Post参数传递,也需要urlencode处理一下。 NSString+URL.h #import <Foundation/Foundation.h> @interface NSString (URL) -(NSString*)encodeString:(NSString* )unencodedString; -(NSString *)decodeString:(NSString* )encodedString; @end NSString+URL.m #import " NSString+URL.h " @implementation NSString (URL) // URLEncode -(NSString*)encodeString:(NSString* )unencodedString{ NSString *encodedString = (NSString * ) CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)unencodedString, NULL, (CFStringRef) @" !*'();