从字符串中删除ASCII符号 [英] Remove ASCII symbol from String

查看:176
本文介绍了从字符串中删除ASCII符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要摆脱一个看起来像



如果您突出显示规格&选择查看选择来源,您会注意到,在单词(可选)之后,它将开始出现在第63行。



如何从String中删除此符号?如果可能的话,是否有办法排除一般的奇怪符号?



编辑2 。尝试两个建议的答案后,我仍然无法将其从String中删除。我现在看到的一个关键部分,我可能已经遗漏了,这个文本是从网站复制到Microsoft Excel中,然后被复制到一个Java Applet(TextArea)中,它被分析和分析。从...操纵。即使在文本区域不可见,它仍然保留在那里,当被复制回到Excel后。



测试代码是:

  String descript = textArea.getText(); 
descript = descript.replace('\\\ ','');
textArea.setText(descript);

将此文本重新导入Excel时,字符仍然保留。

解决方案

这是一个Unicode符号,因此要直接粘贴,您需要使用适当的编码(如UTF-8)编辑文件,您需要使用字体可以显示符号。



在Java字符串中,您可以随时使用Unicode转义来表示字符。男性符号是Unicode U + 2642,所以字符串将是:

 \\\♂

更新:查看网站您引用的字符实际上是一个垂直标签(VT)字符,Unicode U + 000B解释VT看到显示为内联。您可以使用

 \\\

为此。



使用类似

  String newString = oldString.replace('\uBB',''); 

获取一个新的字符串,VT被空格替换。


I need to get rid of a character that looks exactly like the male ascii symbol from text - ♂. However, it's not the standard ASCII symbol, because if I paste it on StackExchange, it's displayed as indicated below:

How can I replace the character within a String? I've tried pasting the character directly into Eclipse but unfortunately that doesn't work (it looks exactly like the image above when pasted into Eclipse). You can see the symbol in Notepad++ however when using the search function:

Howevever, when displayed inline, it looks like this:

Edit: @Greg-449's answer, I've tried that but the character still remains in the String. I don't think it's the default character. I'll show you where you can reference it from a website:

Thermaltake: Chassis > Versa > Versa H21

If you highlight the specifications & choose View selection source you'll notice it start appearing on line 63 after the word (optional).

How can I remove this symbol from the String? If at all possible, is there a way to exclude strange symbols like that in general?

Edit 2. After trying both suggested answers, I'm still not able to remove it from the String. A critical part I now see that I may have left out is that the text is copied from the website, into Microsoft Excel, then into a Java Applet (TextArea) where it is analyzed & manipulated from. Even though not visible in the text area, it still remains there when copied back into Excel after being manipulated.

Code tested is:

String descript = textArea.getText();
descript = descript.replace('\u000B', ' ');
textArea.setText(descript);

When taking this text back into Excel, the character remains.

解决方案

This is a Unicode symbol so to paste it directly you need to be editing a file with a suitable encoding such as UTF-8 and you need to be using a font that can display the symbol.

In a Java string you can always use the Unicode escape to represent the character. The male symbol is Unicode U+2642 so the string would be:

"\u2642"

Update: Looking at the web site you reference the character is actually a 'vertical tab (VT)' character, Unicode U+000B which explains the 'VT' to see 'displayed inline'. You can use

"\u000B"

for this.

Use something like

String newString = oldString.replace('\u000B', ' ');

to get a new string with the VTs replaced by blanks.

这篇关于从字符串中删除ASCII符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆