简体   繁体   English

用特殊字符拆分字符串

[英]Split the String with special character

Could you advise for this special character ?你能为这个特殊的角色提供建议吗? how we can replace and split in java ?我们如何在java中替换和拆分?

Symbol in notepad :-记事本中的符号:- 在此处输入图片说明

Sample Code : Since its has special character.示例代码:因为它具有特殊性。 在此处输入图片说明

If you have only bell characters, you can use:如果您只有铃字符,则可以使用:

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());
}

output:输出:

length with hidden bells: 13
164
3
165
3
165
3

You can also use the hexadecimal notation: \\x07您还可以使用十六进制表示法: \\x07

See: https://www.cisco.com/c/en/us/td/docs/ios/12_4/cfg_fund/command/reference/cfnapph.html请参阅: https : //www.cisco.com/c/en/us/td/docs/ios/12_4/cfg_fund/command/reference/cfnapph.html

Notes:笔记:

If you have different special characters you can create a char class via the hexadecimal values or you can simply use \\D+ if you are only interested in extracting digits from the string or \\\\W+ if your string also contains letters.如果您有不同的特殊字符,您可以通过十六进制值创建一个字符类,或者您可以简单地使用\\D+如果您只想从字符串中提取数字或\\\\W+如果您的字符串还包含字母。 Also if your / is always preceded by a character you want to discard, then ./ should work fine too.此外,如果您的/前面总是有一个您想丢弃的字符,那么./应该可以正常工作。

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

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