开发者

string manipulation in Java: replace spaces and commas with one comma

I am creating a request string which hast to be formatted the following way:

http://staging.myproject.com?tags=tag1,tag2,tag3

There is an EditText dialog on the form where the user writes the tags. The user however can write the tags in the EditText whatever way he wants, for example using commas: tag1, tag2, tag3 or tag1,tag2,tag3 (without spaces) or tag1 tag2 tag3 or for example someone could make multiple spaces between two开发者_运维技巧 tags: tag1 tag, tag3...

I have to make a logic to reshape the content of the EditText the way it matches format

"tag1,tag2,tag3"

(remove spaces, add commas if necessary...).

Does anyone know what is the easiest way to do it in Java?


Try this:

editText = editText.replaceAll("[, ]+", ",");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜