日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
String類的獲取功能、轉(zhuǎn)換功能-創(chuàng)新互聯(lián)

String類的獲取功能:String類的基本獲取功能、獲取功能的舉例子、String類的基本轉(zhuǎn)換功能、轉(zhuǎn)換功能的舉例子、

十年專注成都網(wǎng)站制作,成都定制網(wǎng)站,個人網(wǎng)站制作服務(wù),為大家分享網(wǎng)站制作知識、方案,網(wǎng)站設(shè)計流程、步驟,成功服務(wù)上千家企業(yè)。為您提供網(wǎng)站建設(shè),網(wǎng)站制作,網(wǎng)頁設(shè)計及定制高端網(wǎng)站建設(shè)服務(wù),專注于成都定制網(wǎng)站,高端網(wǎng)頁制作,對集裝箱等多個領(lǐng)域,擁有多年的網(wǎng)站運維經(jīng)驗。

1、String類的獲取功能:

(1)int length()

        獲取字符串的長度,即字符串中字符的個數(shù)。

(2)char charAt(int index)

        獲取指定索引位置上的字符。

(3)int indexOf(int ch)

        獲取指定字符在此字符串中第一次出現(xiàn)的索引。注意:這里用的是int,不是char,原因是'a'和97都可以作為實參傳入。

(4)int indexOf(String str)

        獲取指定字符串在此字符串中第一次出現(xiàn)的索引。

(5)int indexOf(int ch,int fromIndex)

        獲取指定字符在此字符串中指定位置后第一次出現(xiàn)的索引。

(6)int indexOf(String str,int fromIndex)

        獲取指定字符串在此字符串中指定位置后第一次出現(xiàn)的索引。

(7)String substring(int start)

        從指定位置截取子字符串,默認(rèn)是截取到末尾。(包含start位置)

(8)String substring(int start,int end)

        從指定位置開始到指定位置結(jié)束截取子字符串。(包start不包end)

2、獲取功能的舉例

package cn.itcast_06; 
public class StringDemo { 
  public static void main(String[] args) { 
    // int length() 
    // 獲取字符串的長度,即字符串中字符的個數(shù)。 
    String s="helloworld"; 
    System.out.println("length():"+s.length());//10 
    System.out.println("--------------"); 
    // char charAt(int index) 
    // 獲取指定索引位置上的字符。 
    System.out.println("charAt:"+s.charAt(0));//h 
    System.out.println("charAt:"+s.charAt(9));//d 
    System.out.println("--------------"); 
    // int indexOf(int ch) 
    // 獲取指定字符在此字符串中第一次出現(xiàn)的索引。注意:這里用的是int,不是char, 
    // 原因是'a'和97都可以作為實參傳入。 
    System.out.println("indexOf:"+s.indexOf('h'));//0 
    System.out.println("indexOf:"+s.indexOf('d'));//9 
    System.out.println("--------------"); 
    // int indexOf(String str) 
    // 獲取指定字符串在此字符串中第一次出現(xiàn)的索引。 
    System.out.println("indexOf:"+s.indexOf("owo"));//4 
    System.out.println("indexOf:"+s.indexOf("ld"));//8 
    System.out.println("--------------"); 
    // int indexOf(int ch,int fromIndex) 
    // 獲取指定字符在此字符串中指定位置后第一次出現(xiàn)的索引。 
    // int indexOf(String str,int fromIndex) 
    // 獲取指定字符串在此字符串中指定位置后第一次出現(xiàn)的索引。 
    System.out.println("indexOf:"+s.indexOf('l',4));//8 
    System.out.println("indexOf:"+s.indexOf('l',40));//-1 
    System.out.println("--------------"); 
    // String substring(int start) 
    // 從指定位置截取子字符串,默認(rèn)是截取到末尾。(包含start位置) 
    System.out.println("substring:"+s.substring(4));//oworld 
    System.out.println("substring:"+s.substring(0));//helloworld 
    // String substring(int start,int end) 
    // 從指定位置開始到指定位置結(jié)束截取子字符串。(包start不包end) 
    System.out.println("substring:"+s.substring(4,8));//owor 
    System.out.println("substring:"+s.substring(0,s.length()));//helloworld 
  } 
} 

名稱欄目:String類的獲取功能、轉(zhuǎn)換功能-創(chuàng)新互聯(lián)
網(wǎng)頁路徑:http://www.dlmjj.cn/article/ejsgc.html