【发布时间】:2013-04-29 22:58:12
【问题描述】:
我想在一个特定的字符串中提取 Hello world,目前我得到了第一个和最后一个 Occurences。字符串中有 3(三个)hello world 文本,我希望它们在每个特定的字符串上。
String text="hellogfddfdfsdsworldhelloasaasasdasdggworldfdfdsdhellodasasddworld";
int x=text.indexOf("hello");
int y=text.indexOf("world");
String test=text.substring(x, y+4);
System.out.println(test);
x=text.indexOf("hello");
y=text.indexOf("world");
String test1=text.substring(x,y);
System.out.println(test1);
x=text.lastIndexOf("hello");
y=text.lastIndexOf("world);
String test2=text.substring(x, y);
System.out.println(test2);
【问题讨论】:
-
不是真正的专家,但我认为
regex可以满足您的需求!
标签: java string indexing substring