Let’s say I have this:
<value> Some value</value>
Trying to read the value with:
value=someParent.getElementsByTagName("value").item(0).getTextContent().trim();
gives me "Some value"
, but the actual text would be " Some value".
I know trim() leaves out leading and trailing white spaces, but is there an existing method (besides actually adding some lines of code to treat this specific case in particular) in order to have only the trailing white spaces eliminated?
Regular expression can help you :
the
replaceAll()can actually take the place oftrim()in your example :but I would definitly try to make that more readable.