`
hnjzsyjyj
  • 浏览: 27449 次
  • 性别: Icon_minigender_1
  • 来自: 南京
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

substring的用法

 
阅读更多

 

package ch12;

//substring的用法

public class TestSubstring {
	public static void main(String[] args) {
		String phoneNbr="05711681688";
		System.out.println(phoneNbr.substring(0,4)+"-"+phoneNbr.substring(4));
		}
	}


/*String java.lang.String.substring(int beginIndex, int endIndex)
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"*/



/*String java.lang.String.substring(int beginIndex)
Returns a new string that is a substring of this string. The substring begins with 
the character at the specified index and extends to the end of this string. 

Examples: 
"unhappy".substring(2) returns "happy"
"Harbison".substring(3) returns "bison"
"emptiness".substring(9) returns "" (an empty string)*/
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics