st.replaceAll("\s+","")
removes all whitespaces and non-visible characters (e.g., tab,
).
st.replaceAll("\s+","")
and st.replaceAll("\s","")
produce the same result.
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.
Assign the value to a variable, if not used directly:
st = st.replaceAll("\s+","")
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…