ios - html字符串转换为属性字符串与\U00002028\n ios
<p><p>Html 字符串从服务器获取我尝试转换为属性字符串。
使用</p>
<pre><code>NSAttributedString *attributedString = [
initWithData:
options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: }
documentAttributes: nil
error: nil
];
</code></pre>
<p>具有\U00002028\n 的属性字符串会导致显示字符串在文本中出现间距和换行。如何才能删除这样的东西。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>从 NSMutableAttributedString 中修剪前导和尾随空格</p>
<pre><code>NSString * _strAchievementMsg= @"Hi Test the White space ";
NSString * htmlString = ;
NSMutableAttributedString *attString = [
initWithData:
options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: }
documentAttributes: nil
error: nil
];
NSCharacterSet *charSet = ;
NSRange range = ;
while (range.length != 0 && range.location == 0)
{
;
range = ;
}
// Trim trailing whitespace and newlines.
range = [attString.string rangeOfCharacterFromSet:charSet
options:NSBackwardsSearch];
while (range.length != 0 && NSMaxRange(range) == attString.length)
{
[attString replaceCharactersInRange:range
withString:@""];
range = [attString.string rangeOfCharacterFromSet:charSet
options:NSBackwardsSearch];
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - html字符串转换为属性字符串与\U00002028\n ios,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/37915304/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/37915304/
</a>
</p>
页:
[1]