日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

字符串的用法

發布時間:2025/4/16 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 字符串的用法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

 /* 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;

?

轉載于:https://www.cnblogs.com/balopy/p/5210411.html

總結

以上是生活随笔為你收集整理的字符串的用法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。