惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
SegmentFault 最新的问题
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Cisco Talos Blog
Cisco Talos Blog
Spread Privacy
Spread Privacy
Scott Helme
Scott Helme
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Securelist
酷 壳 – CoolShell
酷 壳 – CoolShell
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
I
Intezer
博客园 - 叶小钗
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
雷峰网
雷峰网
量子位
Security Latest
Security Latest
P
Proofpoint News Feed
P
Privacy International News Feed
P
Palo Alto Networks Blog
D
DataBreaches.Net
大猫的无限游戏
大猫的无限游戏
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Google Online Security Blog
Google Online Security Blog
Webroot Blog
Webroot Blog
云风的 BLOG
云风的 BLOG
N
Netflix TechBlog - Medium
Vercel News
Vercel News
博客园 - 【当耐特】
C
CERT Recently Published Vulnerability Notes
Hugging Face - Blog
Hugging Face - Blog
月光博客
月光博客
Hacker News - Newest:
Hacker News - Newest: "LLM"
K
Kaspersky official blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Stack Overflow Blog
Stack Overflow Blog
AWS News Blog
AWS News Blog
博客园 - Franky
爱范儿
爱范儿
T
Tor Project blog
The GitHub Blog
The GitHub Blog
宝玉的分享
宝玉的分享
小众软件
小众软件
L
LINUX DO - 最新话题
Application and Cybersecurity Blog
Application and Cybersecurity Blog
W
WeLiveSecurity
SecWiki News
SecWiki News
L
LangChain Blog
I
InfoQ

博客园 - 龚祺

写在产品公测发布前 如何联机调试和发布程序 在navigationBar上面添加多个任意控件 Post a UIImage to the web 关于String 由pushViewController说起可能出线的各种死法 Sizes of iPhone UI Elements 转载-无言 经过慎重考虑,最终决定上D60 2009项目运行初始 前进的驿站 隆冬季节的随笔 创造一家伟大的公司 卸去浮华 不再浮躁 成功需要积累 如何处理团队意见 感染所有人 思想的力量 猫仔网诞生了 为战斗而生存!
NSString 常用
龚祺 · 2011-11-02 · via 博客园 - 龚祺

Objective-c之NSString(NSMutableString)

2011-06-08 15:13

1、初始化字符串一 

[[NSString alloc] initWithFormat:@"%d",10];  

2、初始化字符串二

[[NSString alloc] initWithCString:@"字符串内容"]  

3、字符串的替换

注:将字符串中的参数进行替换

参数1:目标替换值

参数2:替换成为的值

参数3:类型为默认:NSLiteralSearch

参数4:替换的范围

[str replaceOccurrencesOfString:@"1" withString:@"222" options:NSLiteralSearch range:NSMakeRange(0, [str length])];  

4、给字符串分配容量

  NSMutableString *String;
  String = [NSMutableString stringWithCapacity:40];
 

5、追加字符串

 NSMutableString *String1 = [[NSMutableString alloc] initWithString:@"This is a NSMutableString"];
 [String1 appendFormat:[NSString stringWithFormat:@", I will be adding some character"]];
 

6、在已有字符串中按照所给出范围和长度删除字符

 NSMutableString *String1 = [[NSMutableString alloc] initWithString:@"This is a NSMutableString"];
 [String1 deleteCharactersInRange:NSMakeRange(0, 5)];
 

7、在已有字符串后面在所指定的位置中插入给出的字符串

NSMutableString *String1 = [[NSMutableString alloc] initWithString:@"This is a NSMutableString"];
[String1 insertString:@"Hi! " atIndex:0];
 

8、按照所给出的范围,和字符串替换的原有的字符

 NSMutableString *String1 = [[NSMutableString alloc] initWithString:@"This is a NSMutableString"];
 [String1 replaceCharactersInRange:NSMakeRange(0, 4) withString:@"That"];
 

9、判断字符串内是否还包含别的字符串(前缀,后缀)

NSString *String1 = @"NSStringInformation.txt";
[String1 hasPrefix:@"NSString"] = = 1 ?  NSLog(@"YES") : NSLog(@"NO");
[String1 hasSuffix:@".txt"] = = 1 ?  NSLog(@"YES") : NSLog(@"NO");
 

10、返回一个数组,包含已经由一个给定的分隔符分为接收器串。

- (NSArray*)componentsSeparatedByString:(NSString*)NString

参数
分离器
分隔符的字符串。

NSString *list = @"Norman, Stanley, Fletcher";
NSArray *listItems = [list componentsSeparatedByString:@", "];
listItems包含了:

{ @"Norman", @"Stanley", @"Fletcher" }.

 

11、是否包含该字符串

NSRange range = [@"字符串--A" rangeOfString:“是否包含--B”];


if (range.location == NSNotFound)

{//不包含

}

else

{//包含

}