Krish
Krish

Reputation: 4232

How to remove String Empty space in android

I want to remove empty space from the first String and make it look like the second String.

1)EVANS MD                 JOSEPH       J
2)EVANS MD JOSEPH J

My code:

String finaloriginAutoCompleteText = providerOriginAddress.get(position).getProviderName();

Upvotes: 0

Views: 4036

Answers (1)

Slobodan Antonijević
Slobodan Antonijević

Reputation: 2643

String finaloriginAutoCompleteText;
finaloriginAutoCompleteText = providerOriginAddress.get(position).getProviderName();

// trim the string (for leading and ending whitespaces) and then
// replace all remaining (inner) multiple spaces (\s+) with a single space (" ")
finaloriginAutoCompleteText = finaloriginAutoCompleteText.trim().replaceAll("\\s+", " "); 

Upvotes: 1

Related Questions