[英]Android Detect space in given String and break line
只是一个简单的问题,经过一个小时的研究,我还没有找到解决我问题的方法:
我有一个给定的String (来自在线数据库),其中可能包含空格,并且我需要在每个空格处换行 。
输出必须是字符串
有人可以帮忙吗?
干杯
String newString = oldString.replaceAll(" ","\n");
你可以这样做,例如
String s = I am a dragon.
s.replaceAll(" ", "\n");
你可以拆分
class A{
public static void main(String[] args) {
String word = "Hello Hello Hello Hello ";// Now Your String like This
String arr[] = word.split(" ");// You can Split it from every Space
for (String name : arr) {
System.out.println(name);// output is a String
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.