设为首页 加入收藏

TOP

Java中substring的注意点
2014-11-23 19:27:27 】 浏览:5330
Tags:Java substring 注意

  先上代码,以截取固话区号及不含区号的号码为例:


  1 public class TestSubstring {


  2 public static void main(String[] args) {


  3 String phoneNbr="05718888888";


  4 //对于4位区号应该是substring(0,4),不是substring(0,3)


  5 System.out.println(phoneNbr.substring(0,4)+" "+phoneNbr.substring(4));


  6 }


  7 }


  java API 中的说明:


  Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex.


  Examples:


  "hamburger".substring(4, 8) returns "urge"


  "smiles".substring(1, 5) returns "mile"


  Parameters:


  beginIndex the beginning index, inclusive.


  endIndex the ending index, exclusive.


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Java中Properties类的使用 下一篇为Java程序添加漂亮背景图片

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目