在java中,有没有办法将单词从字符串中拆分出来?
String my ="StackOverFlow PF Apple FT Laptop HW."PF =平台,FT =水果,HW =硬件。
预期输出应为
StackOverFlow is a Platform.
Apple is a Fruit.
Laptop is a hardware.我是这样做的:
String[] words = my.split(" ");
for(int u=0 ; u<words.length ; u++){
System.out.println( words(u));
}发布于 2016-08-25 04:23:59
考虑到你问题中的有限规格,没有理由分开。你可以像这样替换你的占位符:
String my = "StackOverFlow PF Apple FT Laptop HW.";
my = my.replaceAll("PF[\\s.]?", " is a Platform.\n");
my = my.replaceAll("FT[\\s.]?", " is a Fruit.\n");
my = my.replaceAll("HW[\\s.]?", " is a hardware.\n");
System.out.print(my);输出:
StackOverFlow is a Platform.
Apple is a Fruit.
Laptop is a hardware.https://stackoverflow.com/questions/39131976
复制相似问题