简体   繁体   English

如何从nsstring ios中删除字符'\\ U0000fffc'

[英]how to remove characters '\U0000fffc' from nsstring ios

I am developing chat application. 我正在开发聊天应用程序。 In iOS 8, i am sending text and image, while sending image with text a characters "\\U0000fffc" are prefixed to nsstring. 在iOS 8中,我正在发送文本和图像,而在发送带有文本的图像时,字符“ \\ U0000fffc”以nsstring为前缀。

I tried using the below code,but it is not working 我尝试使用以下代码,但无法正常工作

NSCharacterSet *characterset=[NSCharacterSet characterSetWithCharactersInString:@"\\U0000fffc"];
NSString *newString = [str stringByTrimmingCharactersInSet:characterset];

Any help would be appreciated 任何帮助,将不胜感激

Thanks to All who have answered and contributed. 感谢所有回答和贡献的人。 I fixed using below code 我使用以下代码修复了

NSString *codeString = @"\uFFFC";
NSString *msg=[msg stringByReplacingOccurrencesOfString:codeString withString:@""];

If I used above code then compiled errors are fixed and worked....! 如果我使用上面的代码,则已编译的错误已修复并有效。

This is the replacement character (often a black diamond with a white question mark or an empty square box) is a symbol found in the Unicode standard at codepoint U+FFFD in the Specials table. 这是替换字符。(通常是带有白色问号的黑色菱形或一个空的方框)是在Unicode标准中的特殊表中的代码点U + FFFD处找到的符号。 It is used to indicate problems when a system is unable to render a stream of data to a correct symbol. 当系统无法将数据流呈现为正确的符号时,它用于指示问题。 It is usually seen when the data is invalid and does not match any character. 通常在数据无效且不匹配任何字符时看到。

This can be removed as follow 可以如下删除

NSString *codeString = @"\\ufffc";  
NSString *newString=[str stringByReplacingOccurrencesOfString:codeString withString:@""];

PS : " /uFFFC " didn't worked for me. PS:“ / uFFFC ”不适用于我。

NSString *str = @"This is my string \U0000fffc";
NSString *strModified = [str stringByReplacingOccurrencesOfString:@"\U0000fffc" withString:@""]; 
NSLog(@"%@",strModified);

Try this. 尝试这个。 Hope will work for you. 希望能为您服务。 :) :)

Today, I have faced the same situation and after digging in some more I have found that the said character is in fact NSAttachmentCharacter which the function -(void)replaceCharactersInRange:(NSRange)range withAttributedString:(NSAttributedString *)attrString; 今天,我面临着同样的情况,在深入研究之后,我发现该字符实际上是NSAttachmentCharacter ,该函数-(void)replaceCharactersInRange:(NSRange)range withAttributedString:(NSAttributedString *)attrString; adds to your attributed string to mark the position of a NSTextAttachment in your string and you shouldn't replace it anyways. 将添加到属性字符串中以标记NSTextAttachment在字符串中的位置,并且无论如何都不应替换它。 If you are still facing trouble working with your Strings, provide more information about the problem, otherwise, stick to your current implementation. 如果在使用字符串时仍然遇到问题,请提供有关该问题的更多信息,否则,请坚持使用当前的实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM