From Java To Objective C: Strings
My Notes (part 2)
This is a very short introduction from my notes.
A good and complete starting point can be found by google.
The String.
In java we have String Class that represent a string, in objective C there is a NSString object.
Each string constant double quote in objective-c must be prefixed by @
Also in objective C, NSString is immutable like java String.
.objective c version
- NSString aString = @"hello world";
- NSString aString2 = [[NSString alloc] initWithString:@"Hello World2"];
- [aString release];
- #define CONSTANT1 @"HELLO";
- NSLog(@"debug string");
- NSString *ageString = [NSString stringWithFormat:@"%@ concatenate with %@", "age:", 18];
.java version
- String aString = "hello world";
- String aString2 = new String("Hello World 2");
- public static final String CONSTANT1 = "HELLO";
- System.out.println("debug string");
- String ageString = "age:" + " concatenate with " + 18;
12 comments:
Post a Comment