当前位置:网站首页>OC-NSString
OC-NSString
2022-08-02 07:49:00 【Peng classmate her deskmate】
Foundation/NSString.h
String constants are called from the beginning of execution of the program to the termination of the programreleaseNeither method nor garbage collection can release
NSStringRepresents an immutable string object It cannot be changed by additions and deletions
String used internallyUnicode编码
NSStringin a cluster-like manner(class cluster)Think of it as a factory class
定义方式
NSString *a = @"abc";
The compiler will concatenate strings separated by spaces
拼接字符串
stringByAppendingFormat Multiple strings can be concatenated
NSString *a = @"abc";
NSString *c = @"zzzz";
NSString *b = [a stringByAppendingFormat:@"第一个参数: %@ 第二个参数%@",@12,c];//abc第一个参数: 12 第二个参数zzzz
-(NSUInteger)length 获取长度
返回字符串中UnicodeThe number of encoded characters The return value of this function cannot be used to calculate the number of bytes required Because it returns the number of characters But you don't know how many bytes a character occupies
componentsJoinedByString Concatenate strings by specifying symbols
NSArray* array = @[@"a",@"b",@"c"];
NSString *string = [array componentsJoinedByString:@"-"];
NSLog(@"%@",string);
查找字符串
rangeOfString //从stringFind the string inside and return itrange形式变量
找到了 就返回{location,length}
没找到 返回{NSNotFound,0}
NSString *string = @"0123456789abc";
NSRange range = [string rangeOfString:@"34"];
NSLog(@"@",NSStringFromRange(range));//{3,2} 第三个位置 两个字符
NSRange range = [string rangeOfString:@"Ab" options:NSCaseInsensitiveSerch];//添加参数 This is case sensitive
分割字符串
componentsSeparatedByString Split by the specified symbol
NSString *string = @"sbcd-efht-defagfds";
NSArray *array = [string componentsSeparatedByString:@"-"];
NSLog(@"array = %@",array);//array = (sbcd,efht,defagfds)
substringWithRange 通过range分割字符串
NSString *string = @"0123456789abc"
NSRange range ={
3,8};
NSString *newString = [string substringWithRange:range];//从第3Bits start to take eight 3456789a
删除字符串
stringByTrimmingCharactersInSet: 删除特殊符号 Commonly used spaces
NSString * string = @" abcd ";
string = [string stringByTrimmingCharactersInSet:NSCharacterSet whitespaceCharacterSet];//abcd whitespaceCharacterSet是空格
替换字符串
stringByReplacingOccurrencesOfString:withString: 将指定字符串a替换成指定字符串b
NSSstring string = @“lixun”;
NSString *newString = [string stringByReplacingOccurrencesOfString:@"li"withString:@“liu”];将li字符串替换成liu
stringByReplacingCharactersInRange:withString:
NSString * string = @“aaaaaaannnnnnn”;
NSRange range = {4,3};
string = [string stringByReplacingCharactersInRange:range withString:@“qqqqqqqq”];//Indicates that the fourth position will be3个字符替换成qqqqqqqqq //aaaqqqqqqqqannnnnnn
字符串比较
NSString *string1 = @“abc”;
NSString *string2 = @"ABC";
NSComparisonResult rs = [string1 compare:string2];
if(rs == NSOrderedAscending){
NSLog(@"string1<string2")};
else if(rs == NSOrderedSame){
NSLog(@"string1 = string2")};
else{
NSLog(@"string1>string2")};
关于UTF-8的解码方式
因为ASCIISimply using a byte to represent a character causes the text of many countries to be unable to be represented
所以发明了unicode编码 unicodeThere are several ways of encoding UTF-8 UTF-16 UTF-32
UTF-8The biggest feature is the variable length 用1-4个字节表示
1.When only represented by a single byte 第一位设为0 后面7位对应这个字符的Unicode码
2.对于需要使用Ncharacter to represent(N>1)第一个字节的前N位都设为1 第N+1位设为0
The first two bits of the remaining bytes are set10
So if the first one is0It means that one byte corresponds to one character 如果第一位是1 Then see how many consecutive1It indicates how many bytes a character occupies
0xxxxxxx
110xxxxx 10xxxxxx
1110xxxx 10xxxxxx 10xxxxxx
11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
边栏推荐
猜你喜欢
论文阅读 (64):Weakly-supervised Video Anomaly Detection with Robust Temporal Feature Magnitude Learning
正则表达式
A Preliminary Study on the Basic Principles of Formal Methods
Splunk Filed extraction 字段截取
“蔚来杯“2022牛客暑期多校训练营4,签到题NDKHL
FaceBook社媒营销高效转化技巧分享
Mysql报错2003 解决办法 Can‘t connect to MySQL server on ‘localhost‘ (10061)
2020美亚团队赛复盘
Splunk Filed Alias 字段改名
PWA 踩坑 - 第一次加载页面后无法获取CacheStorage某些资源
随机推荐
图腾柱和推挽电路介绍
实例029:反向输出
【图像隐藏】基于matlab混合DWT-HD-SVD数字图像水印方法技术【含Matlab源码 2007期】
gdalinfo: error while loading shared libraries: libgdal.so.30: cannot open shared object file: No su
逆变器绝缘检测检测功能及软件实现
OC-NSNumber and NSValue are generally used for boxing and unboxing
入门opencv,欢笑快乐每一天
FormData上传二进制文件、对象、对象数组
LeetCode 283. Shifting Zeros (Simple, Array)
实验7 MPLS实验
逆变器锁相原理及DSP实现
交换--STP协议
【CNN回归预测】基于matlab卷积神经网络CNN数据回归预测【含Matlab源码 2003期】
【暑期每日一题】洛谷 P3156 【深基15.例1】询问学号
MPLS的相关技术
自然语言处理 文本预处理(上)(分词、词性标注、命名实体识别等)
(Part of it is not understood, and the notes are not completed) [Graph Theory] Difference Constraints
OC-错误提示
请教一下,Flink SQL ,JDBC sink 入 mysql 库,想要搞一个自增主键,要怎么写
【CV】OpenVINO安装教程