st.replaceAll("\\s+","")
removes all whitespaces and non-visible characters (eg, tab, \n
).
(st.replaceAll("\\s+","")
删除所有空格和不可见字符(例如,tab, \n
)。)
st.replaceAll("\\s+","")
and st.replaceAll("\\s","")
produce the same result.
(st.replaceAll("\\s+","")
和st.replaceAll("\\s","")
产生相同的结果。)
The second regex is 20% faster than the first one, but as the number consecutive spaces increases, the first one performs better than the second one.
(第二个正则表达式比第一个正则表达式快20%,但是随着连续空格数量的增加,第一个正则表达式的性能要好于第二个正则表达式。)
Assign the value to a variable, if not used directly:
(将值分配给变量(如果不直接使用):)
st = st.replaceAll("\s+","")
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…