早上,刚到公司。朋友发了一条QQ消息,说怎么得到字符串中某几个字!下面的demo,就是我的解决办法,如果你们有更好的建议,可以在下方评论或者留下联系方式,我们可以一起探讨技术!
public static void main(String[] args) {
String str="北京市朝阳区大区专员";
if(str.indexOf("大区专员")!=-1){//判断是否包含截取的字符
System.out.println("包含");
String jieguo = str.substring(str.indexOf("大"),str.indexOf("员")+1);
System.out.println(jieguo);
}else{
System.out.println("不包含");
}
}
以上是我的解决方法,感谢大家 System.err.println(“纠正”);