London
London

Reputation: 15274

How to make sure that string is valid

I'm parsing XML and for now I use nodeTextValue.length() > 0 to check whether the nodeTextValue is valid string, but I'm having issues with \n \r and so on, preceding and following nodeText, is there an existing class to trim string on both ways not just after so it returns the valid string

I'm using stax

Upvotes: 2

Views: 346

Answers (3)

fastcodejava
fastcodejava

Reputation: 41097

!nodeTextValue().trim().equals("").

Upvotes: 0

Skyler
Skyler

Reputation: 341

You can accomplish this by using the trim function on strings. I would also recommend googling Java regular expressions for validating strings.

Upvotes: 1

Matthew Flaschen
Matthew Flaschen

Reputation: 284786

trim() will remove leading and trailing whitespace.

Upvotes: 5

Related Questions