iOS开发常识
一、NSString 创建字符串。 NSString *astring = @ "This is a String!"; 创建空字符串,给予赋值。 NSString *astring = [[NSString alloc] init]; astring = @ "This is a String!"; NSLog(@ "astring:%@",astring); string release]; 使用变量初始化 NSString *name = @ "Ivan!"; NSString *astring = [[NSString stringWithFormat:@”My name is %@!”,name]]; NSLog(@ "astring:%@",astring); 判断是否包含某字符串 检查字符串是否以另一个字符串开头 - ( BOOL) hasPrefix: (NSString *) aString; NSString *String1 = @ "NSStringInformation.txt"; [String1 hasPrefix:@ "NSString"] == 1 ? NSLog(@ "YES") : NSLog(@ "NO"); [String1 hasSuffix:@ ".txt"] == 1 ? NSLog(@ "YES") : NSLog(@ "NO");