“字符串小问题”
我想让他变成“ 字 符 串 小 问 题 ”
也就是每个字符前后都加上个空格
不知道实现MessageFormat接口的类能不能实现这种情况
还有政则表达式行么?
还有没有其他的解决方法
一个字符一个字符的读出来再加空格可不是一个好办法
我想让他变成“ 字 符 串 小 问 题 ”
也就是每个字符前后都加上个空格
不知道实现MessageFormat接口的类能不能实现这种情况
还有政则表达式行么?
还有没有其他的解决方法
一个字符一个字符的读出来再加空格可不是一个好办法
System.out.println(s.replaceAll("(\\w)"," $1 "));
String strItem = "字符串小";
String[] arguments = strItem.split("");
String strPattern = " ";
for (int i=0 ;i<arguments.length ; ++i){
strPattern += "{"+i+"} ";
}
String result = java.text.MessageFormat.format(strPattern,arguments);
System.out.println("result:"+result);
humanity的方法不错啊
String s = "This is a test case.";
System.out.println(s.replaceAll("(\\w)"," $1 "));
楼上的我在看了之后看见这样一句话,我不是很看的懂,但我觉得应该对你有帮助。
Note that backslashes (\) and dollar signs ($) in the replacement string may cause the results to be different than if it were being treated as a literal replacement string. Dollar signs may be treated as references to captured subsequences as described above, and backslashes are used to escape literal characters in the replacement string.
System.out.println(s.replaceAll("(\\w)"," $1 "));中文不行啊
用在中文都不行啊
replaceAll(""," ");
这个都可以啊
System.out.println(s.replaceAll("([\\w|\\u4e00-\\u9fa5])"," $1 "));
String s = "字符串小问题.";
System.out.println(s.replaceAll("(\\w)"," $1 "));
可以阿
String s = "字符串小问题.";
s =s.replaceAll("(\\w)"," $1 ");
System.out.println("First Time ReplaceAll Result: "+s);
System.out.println(s.length());
System.out.println("_______________________");
s =s.replaceAll("([\\w|\\u4e00-\\u9fa5])"," $1 ");
System.out.println("Second Time ReplaceAll Result: "+s);
System.out.println(s.length());
我的运行结果:
First Time ReplaceAll Result: 字符串小问题.
7
_______________________
Second Time ReplaceAll Result: 字 符 串 小 问 题 .
19
如果你的运行结果真的是可以,请告知我.