iOS 字符窜

字符串常用方法

复制代码
  
  
int main ( int argc, const char * argv[])
{
NSAutoreleasePool
* pool = [[NSAutoreleasePool alloc] init];
// 字符串的创建和初始化
NSString * sFormat = [[NSString alloc] initWithFormat: @" Year:%d " , 2009 ];
NSString
* sString = [[NSString alloc] initWithString:sFormat];
NSString
* sTmp = nil;
// 获取长度
NSUInteger uLen = [sFormat length];
NSLog(
@" uLen = %u " , uLen);
// 获取指定索引处的字符
NSUInteger index = 0 ;
unichar c
= [sFormat characterAtIndex:index];
NSLog(
@" The character at index %u of \ " % @\ " is \'%c\' " , index, sFormat, c);
// 字符串大小写转换
/*
Case transformations aren’t guaranteed to be symmetrical or to
produce
strings of the same lengths as the originals. The result of this
statement:
lcString = [myString lowercaseString];
might not be equal to this statement:
lcString = [[myString uppercaseString] lowercaseString];
For example, the uppercase form of “ß” in German is “SS”, so
converting
“Straße” to uppercase, then lowercase, produces this sequence of
strings:
“Straße”
“STRASSE”
“strasse”
*/
sTmp
= [sFormat lowercaseString];
NSLog(
@" Lowercase String of %@ is %@ " , sFormat, sTmp);
sTmp
= [sString uppercaseString];
NSLog(
@" Uppercase String of %@ is %@ " , sString, sTmp);
// 字符串比较
// 地址比较
if ( @" Year:2009 " == sFormat) {
NSLog(
@" The address of sFormat is equal to constant string \ " Year: 2009 \ "" );
}
else
{
NSLog(
@" The address of sFormat isn't equal to constant string \ " Year: 2009 \ "" );
}
// 内容比较
复制代码
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值