str="iamhere';str.match('amh');可以匹配上,现在,我需要返回1,3两个数字,分别是匹配的起始结束位置。可否做到?
1 回答

慕婉清6462132
TA贡献1804条经验 获得超2个赞
package test;public class Test { public static void main(String[] args) { String str = "iamhere"; System.out.println("起始位置: " + str.indexOf("amh")); System.out.println("结束位置: " + (str.indexOf("amh") + "amh".length() - 1)); } }
运行结果:
起始位置: 1
结束位置: 3
添加回答
举报
0/150
提交
取消