简体   繁体   English

["如何在java中删除字符串“\”"]

[英]How to remove string "\u001b[1m" in java

["

After I receive a content response of the server, and print the content to console and I realize existing of the string "\", and I think it's the reason I can't parse the conte tresponse as a JSON object.<\/i>在收到服务器的内容响应并将内容打印到控制台后,我意识到字符串“\”的存在,我认为这是我无法将 conte tresponse 解析为 JSON 对象的原因。<\/b><\/p>

And I want to remove the string, any solution?<\/i>我想删除字符串,有什么解决方案吗?<\/b><\/p>"]

That looks like an ANSI video escape sequence to turn bold mode on.这看起来像一个 ANSI 视频转义序列来打开粗体模式。 Are you sure that the server is sending back a JSON object?您确定服务器正在发回 JSON 对象吗?

["

During the development of an SSH program that also utilizes command line mysql commands, I created the following regex that I strip these sequences with:<\/i>在开发也使用命令行 mysql 命令的 SSH 程序期间,我创建了以下正则表达式,我用它来剥离这些序列:<\/b><\/p>

\u001b[\[\(]([0-9];[0-9]|\?[0-9]+)?[Bmh]

Make sure you know what's actually in the string -- try examining (and maybe printing) it character by character using someString.charAt() .确保您知道字符串中的实际内容——尝试使用someString.charAt()逐个字符地检查(并可能打印)它。

And, String newString = someString.replaceAll(oldexp);并且, String newString = someString.replaceAll(oldexp); is one of many ways you might try to "fix" it, if it turns out that's needed.是您可能尝试“修复”它的众多方法之一,如果事实证明这是必要的。

That's an escape sequence, and I think it's used to turn on formatting in some things like the Terminal.这是一个转义序列,我认为它用于在终端等某些东西中打开格式。 Is that really supposed to be JSON?那真的应该是JSON吗? What's the rest of the text?剩下的文字是什么? Does that escape sequence come as plain text or as one character?该转义序列是纯文本还是一个字符?

["
sed  -E 's/\\u001b\[[0-9][0-9]?m//g'

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

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