java中字符串的截取
生活随笔
收集整理的這篇文章主要介紹了
java中字符串的截取
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、length()函數 字符串的長度
? ?
<span style="font-size:18px;"> char chars[]={'a','b'.'c'};String s=new String(chars);int len=s.length();</span> ?2、charAt()截取一個字符 在某個下標的地址? ? ?
<span style="font-size:18px;"> char ch;ch="abc".charAt(1); 返回'b'</span> 3、getChars()函數獲取多個字符串? ?void getChars(int sourceStart,int?sourceEnd,char target[],int targetStart)
sourceStart指定了子串開始字符的下標,sourceEnd指定了子串結束后的下一個字符的下標。因此,子串包含從sourceStart到sourceEnd-1的字符。
接收字符的數組由target指定,target中開始復制子串的下標值是targetStart。
? ?
String s="this is a demo of the getChars method."; char buf[]=new char[20]; s.getChars(10,14,buf,0); 4、getBytes()函數? ??替代getChars()的一種方法是將字符存儲在字節數組中,該方法即getBytes()。
5、toCharArray()函數 ??
? ? 將字符串對象中的字符轉換成一個字符數組
總結
以上是生活随笔為你收集整理的java中字符串的截取的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 怎么在Caffe中配置每一个层的结构
- 下一篇: java中的compareTo函数