字符串的用法
/* 1. 删除字符串里面的空格,包括首、尾空格*/
NSString *urlString = @" 4245 25424 24545242 324234234 524234 ";
NSString *strUrl = [urlString stringByReplacingOccurrencesOfString:@" " withString:@""];
// 删除空格, 也就意味着,把字符串里面的空格,用给替换掉。
// 替换字符串中的某一段字符串使用 stringByReplacingOccurrencesOfString 方法
NSString *replace = [urlString stringByReplacingOccurrencesOfString:@"24545242" withString:@"我的家在中国"];
NSLog(@"----replace--%@",replace);
NSLog(@"---首尾----%@",content);
/* 去除首尾空格和换行:把字符串放到集合中, 由系统方法,去掉首尾空格*/
NSString *content = [urlString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSLog(@"---换行----%@",contents);
/* 改变字符串中某些字符的颜色,大小 */
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"Change NSAttributed String color and font"];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,5)];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(6,12)];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(19,6)];
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial-BoldItalicMT" size:30.0] range:NSMakeRange(0, 5)];
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:30.0] range:NSMakeRange(6, 12)];
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Courier-BoldOblique" size:30.0] range:NSMakeRange(19, 6)];
UILabel *labe = [[UILabel alloc] init];
labe.titleLabel.attributedText = str;