0
我想从第一个字符串中删除空白空间,并使其看起来像第二个字符串。如何删除字符串空的空间android
1)EVANS MD JOSEPH J
2)EVANS MD JOSEPH J
我的代码:
String finaloriginAutoCompleteText = providerOriginAddress.get(position).getProviderName();
我想从第一个字符串中删除空白空间,并使其看起来像第二个字符串。如何删除字符串空的空间android
1)EVANS MD JOSEPH J
2)EVANS MD JOSEPH J
我的代码:
String finaloriginAutoCompleteText = providerOriginAddress.get(position).getProviderName();
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+", " ");
所以我们如何在开始和结束时使用空格来删除,以及如何删除内部多余的空格 – Krish
@Krish现在看到答案我刚刚编辑它 –
finaloriginAutoCompleteText.trim(); 说明:它将返回此字符串的副本,并删除前导空白和尾部空白,或者如果此字符串没有前导或尾随空白,则返回此字符串的副本。 –
没有不工作 – Krish
可能的重复[如何删除字符串中使用Java重复的空格?](http://stackoverflow.com/questions/3958955/how-to-remove-duplicate-white-spaces-in-string -using-java) –