猿问
可以返回匹配的位置吗?
str="iamhere';str.match('amh');
可以匹配上,现在,我需要返回1,3两个数字,分别是匹配的起始结束位置。
可否做到?
慕雪6442864
浏览 782
回答 1
1回答
慕婉清6462132
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
0
0
随时随地看视频
慕课网APP
相关分类
JavaScript
我要回答