我有一个EditText视图,允许用户编辑地址字段。我希望任何带有逗号的文本放在新行之前,例如以下内容:
Some St., Some City, Some post code
将显示为:
Some St.,
Some City,
Some post code
任何人都知道我该怎么做?
答案 0 :(得分:3)
也许您可以执行String.replace()
将所有逗号替换为,\n
所以,
String s = "Some St., Some City, Some post code"
s = s.replace(",",",\n");
然后你可能需要做一些事情来删除空白
或者,删除所有空格:
String s = "Some St., Some City, Some post code";
String strings[] = s.split(",");
for(int i = 0; i < strings.length; i++){
strings[i] = strings[i].trim();
strings[i] += ",\n";
}
s = "";
for(int i = 0; i < strings.length; i++)
s += strings[i];