您的位置:首页 > 其它

115,字符串替代

2015-12-20 10:18 225 查看
#import <Foundation/Foundation.h>

int main(int argc,
const char * argv[]) {

/*

OccurrencesOfString:被替换者,

withString:替换者

*/

NSString *str =
@"http:$$www.baidu.com$content$1012.html";

NSString *newStr = [str
stringByReplacingOccurrencesOfString:@"$"
withString:@"/"];

NSLog(@"newStr = |%@|",newStr);

/*

首尾替换

*/

NSString *str1 =
@" http://www.baidu.com/content/1012.html ";

NSCharacterSet *set = [NSCharacterSet
whitespaceCharacterSet];

NSString *newStr1 = [str1
stringByTrimmingCharactersInSet:set];

NSLog(@"newStr1 = |%@|",newStr1);

return 0;

}

//2015-12-20 10:17:17.734 10,字符串替换[1143:119825] newStr = |http://www.baidu.com/content/1012.html|

//2015-12-20 10:17:17.735 10,字符串替换[1143:119825] newStr1 = |http://www.baidu.com/content/1012.html|

//Program ended with exit code: 0
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: