Reputation: 1
Am trying to trim a string which has multi-line whitespace and also a single-whitespace ... I want to only remove the multi-line whitespace which varies in different length ex. " ", " ", Can anyone please help me on this and also thank you in advance
I tried trim, replaceALL method with REG(\s) pattern but they are not giving the results in want
Upvotes: 0
Views: 389
Reputation: 3897
Line breaks are encoded by special characters that are different to a regular space. Usually, they are represented by "\n", whereas a whitespace is just " ". So for your usecase, a command like
modifiedString = originalString.replace("\n","")
will do the trick. It replaces all newlines by a 0-length string, thus removing it.
If you want to dive deep into the topic, it will also be interesting to look into the differences of "\r" and "\n".
Upvotes: 1