Ignore whitespace in HTML [duplicate]

Oh, you can really easy accomplish that with a single line of CSS: #parent_of_imgs { white-space-collapse: discard; } Disadvantage, you ask? No browser has implemented this extremely useful feature (think of inline blocks in general) yet. 🙁 What I did from time to time, although it’s ugly as the night is dark, is to use … Read more

Removing whitespace from strings in Java

st.replaceAll(“\\s+”,””) removes all whitespaces and non-visible characters (e.g., tab, \n). 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 = … Read more

How to split a string with any whitespace chars as delimiters

Something in the lines of myString.split(“\\s+”); This groups all white spaces as a delimiter. So if I have the string: “Hello[space character][tab character]World” This should yield the strings “Hello” and “World” and omit the empty space between the [space] and the [tab]. As VonC pointed out, the backslash should be escaped, because Java would first … Read more