Does objective c have a strip tags function?(目标 c 有带标签功能吗?)
本文介绍了目标 c 有带标签功能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一个目标 C 函数(自定义或内置),它可以从字符串中去除 html 标记,类似于可以在此处找到的 PHP 版本:
I am looking for an objective C function (custom or built-in) that strips html tags from a string, similar to PHP's version that can be found here:
http://php.net/manual/en/function.strip-tags.php
任何帮助将不胜感激!
推荐答案
这只是删除 <
和 >
字符以及它们之间的所有内容,我认为这已经足够了:
This just removes <
and >
characters and everything between them, which I suppose is sufficient:
- (NSString *) stripTags:(NSString *)str
{
NSMutableString *ms = [NSMutableString stringWithCapacity:[str length]];
NSScanner *scanner = [NSScanner scannerWithString:str];
[scanner setCharactersToBeSkipped:nil];
NSString *s = nil;
while (![scanner isAtEnd])
{
[scanner scanUpToString:@"<" intoString:&s];
if (s != nil)
[ms appendString:s];
[scanner scanUpToString:@">" intoString:NULL];
if (![scanner isAtEnd])
[scanner setScanLocation:[scanner scanLocation]+1];
s = nil;
}
return ms;
}
这篇关于目标 c 有带标签功能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:目标 c 有带标签功能吗?


猜你喜欢
- SetOnItemSelectedListener上的微调程序错误 2022-01-01
- GPS状态的广播接收器? 2022-01-01
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01
- URL编码Swift iOS 2022-01-01
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01
- UITextView 内容插图 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01