How do I declare a simple string "test" to a variable?
NSString from C Strings and Data To create an NSString object from a C string, you use methods such as initWithCString:encoding: . You must correctly specify the character encoding of the C string. Similar methods allow you to create string objects from characters in a variety of encodings.
You can use %@ for all objects including NSString. This will in turn call the objects description method and print the appropriate string.
You want: NSString *firstLetter = [codeString substringToIndex:1];
A static, plain-text Unicode string object that bridges to String ; use NSString when you need reference semantics or other Foundation-specific behavior.
A C string is just like in C.
char myCString[] = "test";
An NSString uses the @
character:
NSString *myNSString = @"test";
If you need to manage the NSString's memory:
NSString *myNSString = [NSString stringWithFormat:@"test"]; NSString *myRetainedNSString = [[NSString alloc] initWithFormat:@"test"];
Or if you need an editable string:
NSMutableString *myMutableString = [NSMutableString stringWithFormat:@"test"];
You can read more from the Apple NSString documentation.
NSString *testString = @"test";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With