iOS NSString的api經常使用解析html
標籤:nsstring objectvie-c apiweb
一、建立常量字符串。api
1
|
NSString *astring = @
"This is a String!"
;
|
二、建立空字符串,給予賦值。ide
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
NSString *astring = [[NSString alloc] init];
astring = @
"This is a 59wan.cn website!"
;
[astring release];
NSLog(@
"astring:%@"
,astring);
//
NSString *astring = [[NSString alloc] init];
NSLog(@
"0x%.8x"
, astring);
astring=@
"This is a String!"
;
NSLog(@
"0x%.8x"
, astring);
[astring release];
NSLog(@
"astring:%@"
,astring);
|
三、在以上方法中,提高速度:initWithString方法spa
1
2
3
4
5
|
NSString *astring = [[NSString alloc] initWithString:@
"This is a String!"
];
NSLog(@
"astring:%@"
,astring);
[astring release];
|
四、用標準c建立字符串:initWithCString方法code
*Cstring = ; NSString *astring = [[NSString alloc] initWithCString:Cstring]; NSLog(,astring); [astring release];
五、建立格式化字符串:佔位符(由一個%加一個字符組成)orm
i = ; j = ; NSString *astring = [[NSString alloc] initWithString:[NSString stringWithFormat:,i,j]]; NSLog(,astring); [astring release];
六、建立臨時字符串htm
NSString *astring; astring = [NSString stringWithCString:]; NSLog(,astring);