Could you advise for this special character ? how we can replace and split in java ?
最佳答案
如果您只有响铃字符,您可以使用:
String data="164/165/165"; //the hidden bells are there, generated via echo $'164\a/165\a/165' | pbcopy
System.out.println("length with hidden bells: "+data.length());
String elems [] = data.split("\\a/");
for(String e:elems) {
System.out.println(e);
System.out.println(e.length());
}
输出:
length with hidden bells: 13
164
3
165
3
165
3
您还可以使用十六进制表示法:\x07
参见: https://www.cisco.com/c/en/us/td/docs/ios/12_4/cfg_fund/command/reference/cfnapph.html
注释:
如果您有不同的特殊字符,您可以通过十六进制值创建 char 类,或者如果您只想从字符串或 \\中提取数字,则可以简单地使用
如果您的字符串还包含字母。另外,如果您的 \D+
W+/
前面始终是您想要丢弃的字符,那么 ./
也应该可以正常工作。
关于java - 用特殊字符分割字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56681374/