欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > > 文章正文

substring的用法总结,substring用法总结

来源: javaer 分享于  点击 2046 次 点评:33

substring的用法总结,substring用法总结


原文链接:
https://blog.csdn.net/yhs17865569668/article/details/78189525 https://blog.csdn.net/u010892253/article/details/54892676

public class substring {

    public static void main(String[] args) {

        String id = "123454321";

        String shortId, longId, Id;

        shortId = id.substring(2, 7);

        longId = id.substring(1, 8);

        Id = id.substring(4);

        System.out.println("shortId===>" + shortId);

        System.out.println("longId===>" + longId);

        System.out.println("Id===>" + Id);

    }

}
//substring(x)是从字符串的的第x个字符截取
//substring(x,y)是从x到y前的位置停止

结果:

shortId===>34543

longId===>2345432

Id===>54321

用法总结:
1 取字符串的前i个字符

str=str.Substring(0,i); // or str=str.Remove(i,str.Length-i);

2 去掉字符串的前i个字符:

str=str.Remove(0,i); // or str=str.Substring(i); 

3 从右边开始取i个字符:

str=str.Substring(str.Length-i); // or str=str.Remove(0,str.Length-i); 

4 从右边开始去掉i个字符:

str=str.Substring(0,str.Length-i); // or str=str.Remove(str.Length-i,i);

版权说明:感谢原作者的辛苦创作,如转载涉及版权等问题,我们将在第一时间删除,谢谢。
联系邮箱:906083650@qq.com

相关文章

    暂无相关文章

用户点评