iOS开发之一些字符串常用的代码

1、判断字符串是否相等使用isEqualToString:

   NSString *astring01 = @"This is a String!";
NSString
*astring02 = @"This is a String!";
BOOL result
= [astring01 isEqualToString:astring02];
NSLog(
@"result:%d",result);

2、判断字符不相等:

NSString *astring01 = @"This is a String!";    
NSString
*astring02 = @"This is a String!";
if ([astring01 compare: astring02]!=NSOrderedSame )
{
NSLog(
@"not equal");
}

3、判断字符串是否为空。

NSString *urlString = [urlInput stringValue]; 


if (!urlString) {


NSLog( @”NO INPUT.” );


}
else {

if ([urlString length] == 0 ) {


NSLog( @”NO INPUT.” );


}
else {


}


}
}

你可能感兴趣的:(iOS开发之一些字符串常用的代码)