bru*_*h51 2 replace objective-c nsstring str-replace ios
我想替换字符串中的字符串.让我来解释一下我的目标是什么.
这是我的字符串
<p>Hello Webseite i want to replace<p>thisPTag</p>which is in the middle
of the word or in the end of the sentence</p>.
Run Code Online (Sandbox Code Playgroud)
如果我使用
[string stringByReplacingOccurrencesOfString:@"<p>" withString:@"|break|"];
Run Code Online (Sandbox Code Playgroud)
它只取代了第一个
.但是我想要替换所有的p标签,无论是否在句子中,在此之前或之后的空白也无关紧要.
那我该怎么做呢?
不是很重要,但很高兴知道:
请记住,我不想删除html,我只是想替换p-tag来设置中断以获得正确的SSML和TTS(textto speech)
它工作(所有<p>都被替换).你可能只是困惑<p>而且</p>.这些是不同的文字,因此必须单独更换:
NSString * a = @"<p>Hello Webseite i want to replace<p>thisPTag</p>which is in the middle of the word or in the end of the sentence</p>. ";
NSString * b = [a stringByReplacingOccurrencesOfString:@"<p>" withString:@"|break|"];
b = [b stringByReplacingOccurrencesOfString:@"</p>" withString:@"|break|"];
NSLog(@"%@",b);
Run Code Online (Sandbox Code Playgroud)
这打印:
| break |你好Webseite我想替换| break | thisPTag | break |,它位于单词的中间或句子的末尾.
| 归档时间: |
|
| 查看次数: |
1428 次 |
| 最近记录: |