Reputation: 15089
I am doing this on my String right now: .replaceAll("[^A-Za-z0-9]"," ").toLowerCase()
Gives me something like this:
yg jarang orang perasan pernah tak korang perasan dlm mickey mouse dulu http
I want to make sure those unnecessary whitespaces are minimized.
I tried .trim()
but to no avail.
Upvotes: 0
Views: 28
Reputation: 8947
Try this:
.replaceAll("[^A-Za-z0-9]+"," ").toLowerCase()
More:
trim() deletes all whitespace characters before and after your string. It doesn't touch ones in the middle.
Upvotes: 1
Reputation: 178363
You can add the +
metacharacter, which means "one or more matches".
.replaceAll("[^A-Za-z0-9]+"," ").toLowerCase()
This will replace one or more non-letter, non-punctuation characters with exactly one space.
Upvotes: 3