零基础 Object-C 学习路线推荐 : Object-C 学习目录 >> Object-C 基础
零基础 Object-C 学习路线推荐 : Object-C 学习目录 >> Object-C 线程
零基础 Object-C 学习路线推荐 : Object-C 学习目录 >> OpenGL ES
零基础 Object-C 学习路线推荐 : Object-C 学习目录 >> GPUImage
零基础 Object-C 学习路线推荐 : Object-C 学习目录 >> AVFoundation
零基础 Object-C 学习路线推荐 : Object-C 学习目录 >> CocoaPods
一.NSString 替换字符串函数简介
/* Replace all occurrences of the target string in the specified range with replacement. Specified compare options are used for matching target. If NSRegularExpressionSearch is specified, the replacement is treated as a template, as in the corresponding NSRegularExpression methods, and no other options can apply except NSCaseInsensitiveSearch and NSAnchoredSearch.
*/
- (NSString *)stringByReplacingOccurrencesOfString:(NSString *)target withString:(NSString *)replacement options:(NSStringCompareOptions)options range:(NSRange)searchRange ;
/* Replace all occurrences of the target string with replacement. Invokes the above method with 0 options and range of the whole string.
*/
- (NSString *)stringByReplacingOccurrencesOfString:(NSString *)target withString:(NSString *)replacement;
/* Replace characters in range with the specified string, returning new string.
*/
- (NSString *)stringByReplacingCharactersInRange:(NSRange)range withString:(NSString *)replacement ;
二.NSString 替换字符串使用
1.stringByReplacingOccurrencesOfString
/******************************************************************************************/
//@Author:猿说编程
//@Blog(个人博客地址): www.codersrc.com
//@File:iOS NSString 替换字符串
//@Time:2021/09/07 08:00
//@Motto:不积跬步无以至千里,不积小流无以成江海,程序人生的精彩需要坚持不懈地积累!
/******************************************************************************************/
NSString* src = @"www.codersrc.com";
//将字符串 www 替换为字符串 com
NSString* dst = [src stringByReplacingOccurrencesOfString:@"www" withString:@"com"];
/*
Printing description of dst:
com.codersrc.com
*/
2.stringByReplacingCharactersInRange
/******************************************************************************************/
//@Author:猿说编程
//@Blog(个人博客地址): www.codersrc.com
//@File:iOS NSString 替换字符串
//@Time:2021/09/07 08:00
//@Motto:不积跬步无以至千里,不积小流无以成江海,程序人生的精彩需要坚持不懈地积累!
/******************************************************************************************/
NSString* src = @"www.codersrc.com";
//把指定位置的字符串替换为字符串 com
NSString* dst = [src stringByReplacingCharactersInRange:NSMakeRange(0, 1) withString:@"com"];
/*
Printing description of dst:
comww.codersrc.com
*/
三.猜你喜欢
- Xcode – The application’s Info.plist does not contain CFBundleShortVersionString.
- Xcode – This app has attempted to access privacy-sensitive data without a usage description.
- Xcode – Embedded binary’s bundle identifier is not prefixed with the parent app’s bundle identifier
- Xcode – Your maximum App ID limit has been reached. You may create up to 10 App IDs every 7 days
- Xcode replace 使用正则表达式替换文字
- Object-C 获取系统字体和字体名字
- Object-C 加载 TTF/OTF/TTC 文件
- Object-C private var mobileDevice文件夹
- Object-C 保存文件到相册
- iOS NSString 字符串的排序
- iOS NSString 创建和初始化
- iOS UIImage 与 RGBA 相互转换
- iOS NSString 查找指定字符串出现的次数
- iOS NSString 查找指定字符串位置
- iOS NSString 拆分字符串
- iOS NSString 截取字符串
- iOS NSString 和 NSArray 相互转换
- iOS NSString 包含字符串/匹配字符串
- iOS NSString 创建和初始化
- iOS NSString 替换字符串
ChatGPT 3.5 国内中文镜像站免费使用啦
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容