怎样才能去除掉字符串中的标点符号与空格?
帮帮忙……
14 个解决方案
#1
replace(“,”,“”)
replace(“;”,“”)
replace(“;”,“”)
#2
String.replaceAll("[,; ]+", "");
不行就加\转义下。
不行就加\转义下。
#3
"ab c, d. 3 ? 5".replaceAll("[\\p{Punct}\\p{Space}]+", ""); // abcd35
#4
String.replaceAll("[\\p{Punct}\\s]+", "")
#5
+1
#6
str.replaceAll("[\\p{Punct}\\p{Space}]+", "");
#7
用replace啊!
#8
+1
建议你看下API,里面对正则表达式的各种用法说得很详细。
#9
str.replaceAll("[\\p{Punct}\\p{Space}]+", "");就好了,如果需要,给你一个正则表达式,将所有非英文和数字的其他字符全部换成你想要的结果
#10
\p{Lower} A lower-case alphabetic character: [a-z]
\p{Upper} An upper-case alphabetic character:[A-Z]
\p{ASCII} All ASCII:[\x00-\x7F]
\p{Alpha} An alphabetic character:[\p{Lower}\p{Upper}]
\p{Digit} A decimal digit: [0-9]
\p{Alnum} An alphanumeric character:[\p{Alpha}\p{Digit}]
\p{Punct} Punctuation: One of !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
\p{Graph} A visible character: [\p{Alnum}\p{Punct}]
\p{Print} A printable character: [\p{Graph}\x20]
\p{Blank} A space or a tab: [ \t]
\p{Cntrl} A control character: [\x00-\x1F\x7F]
\p{XDigit} A hexadecimal digit: [0-9a-fA-F]
\p{Space} A whitespace character: [ \t\n\x0B\f\r]
\p{Upper} An upper-case alphabetic character:[A-Z]
\p{ASCII} All ASCII:[\x00-\x7F]
\p{Alpha} An alphabetic character:[\p{Lower}\p{Upper}]
\p{Digit} A decimal digit: [0-9]
\p{Alnum} An alphanumeric character:[\p{Alpha}\p{Digit}]
\p{Punct} Punctuation: One of !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
\p{Graph} A visible character: [\p{Alnum}\p{Punct}]
\p{Print} A printable character: [\p{Graph}\x20]
\p{Blank} A space or a tab: [ \t]
\p{Cntrl} A control character: [\x00-\x1F\x7F]
\p{XDigit} A hexadecimal digit: [0-9a-fA-F]
\p{Space} A whitespace character: [ \t\n\x0B\f\r]
#11
使用正则表达式:调用replceAll方法
或去掉指定的符号:string.replce("?");
或去掉指定的符号:string.replce("?");
#12
replaceAll ~~~
#13
String.replaceAll("[\\p{Punct}\\s]+", "")
#14
+1
#1
replace(“,”,“”)
replace(“;”,“”)
replace(“;”,“”)
#2
String.replaceAll("[,; ]+", "");
不行就加\转义下。
不行就加\转义下。
#3
"ab c, d. 3 ? 5".replaceAll("[\\p{Punct}\\p{Space}]+", ""); // abcd35
#4
String.replaceAll("[\\p{Punct}\\s]+", "")
#5
+1
#6
str.replaceAll("[\\p{Punct}\\p{Space}]+", "");
#7
用replace啊!
#8
+1
建议你看下API,里面对正则表达式的各种用法说得很详细。
#9
str.replaceAll("[\\p{Punct}\\p{Space}]+", "");就好了,如果需要,给你一个正则表达式,将所有非英文和数字的其他字符全部换成你想要的结果
#10
\p{Lower} A lower-case alphabetic character: [a-z]
\p{Upper} An upper-case alphabetic character:[A-Z]
\p{ASCII} All ASCII:[\x00-\x7F]
\p{Alpha} An alphabetic character:[\p{Lower}\p{Upper}]
\p{Digit} A decimal digit: [0-9]
\p{Alnum} An alphanumeric character:[\p{Alpha}\p{Digit}]
\p{Punct} Punctuation: One of !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
\p{Graph} A visible character: [\p{Alnum}\p{Punct}]
\p{Print} A printable character: [\p{Graph}\x20]
\p{Blank} A space or a tab: [ \t]
\p{Cntrl} A control character: [\x00-\x1F\x7F]
\p{XDigit} A hexadecimal digit: [0-9a-fA-F]
\p{Space} A whitespace character: [ \t\n\x0B\f\r]
\p{Upper} An upper-case alphabetic character:[A-Z]
\p{ASCII} All ASCII:[\x00-\x7F]
\p{Alpha} An alphabetic character:[\p{Lower}\p{Upper}]
\p{Digit} A decimal digit: [0-9]
\p{Alnum} An alphanumeric character:[\p{Alpha}\p{Digit}]
\p{Punct} Punctuation: One of !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
\p{Graph} A visible character: [\p{Alnum}\p{Punct}]
\p{Print} A printable character: [\p{Graph}\x20]
\p{Blank} A space or a tab: [ \t]
\p{Cntrl} A control character: [\x00-\x1F\x7F]
\p{XDigit} A hexadecimal digit: [0-9a-fA-F]
\p{Space} A whitespace character: [ \t\n\x0B\f\r]
#11
使用正则表达式:调用replceAll方法
或去掉指定的符号:string.replce("?");
或去掉指定的符号:string.replce("?");
#12
replaceAll ~~~
#13
String.replaceAll("[\\p{Punct}\\s]+", "")
#14
+1