Java 中 substring() 方法示例:从字符串中提取子字符串
代码示例:
int x = 23456;
System.out.println(x.toString().substring(2, 4));
结果:
'45'
解释:
x.toString()将整数x转换为字符串 '23456'。substring(2, 4)从字符串 '23456' 中提取从索引 2 开始(包含索引 2)到索引 4 结束(不包含索引 4)的子字符串,即 '45'。
因此,代码输出 '45'。
原文地址: https://www.cveoy.top/t/topic/mXBA 著作权归作者所有。请勿转载和采集!