<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 19, comments - 53, trackbacks - 0, articles - 283
      BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

    String 工具類的常用操作方法大全

    Posted on 2009-07-22 22:54 Gavin.lee 閱讀(645) 評論(0)  編輯  收藏 所屬分類: java SE & EE

    受傷了,今天才知道字符串可以按照通配符來用其他串替換掉通配符,還是PHP的同事,他一語中的,我查了一下,真的可以,所以系統(tǒng)的看了一下String類,都試了一下,不藏私:

    package com.Gavin.tools;

    import org.apache.log4j.Logger;


    public class StrFormat {

        
    private static Logger logger = Logger.getLogger(StrFormat.class);
        
    public static void main(String[] args) {
            
            String test 
    = "http://wap.%s.com/";
            
            String testStr 
    = String.format(test, "500wan");        //給定參數替換掉test中的通配符
            
            logger.debug(testStr);
            
            logger.debug(testStr.charAt(
    0));    //取出testStr的第一個字符
            
            logger.debug(testStr.compareTo(
    "http"));    //testStr與http比較字典序,被比較的在前的返回正整數,在后的負整數,當相等時,返回0
            
            logger.debug(testStr.concat(
    "trade/"));
            
            logger.debug(testStr.indexOf(
    "a"));
            
            logger.debug(testStr.indexOf(
    "p"4));
            
            logger.debug(String.valueOf(
    5));    //將其他類型轉換成String
            
            logger.debug(testStr.startsWith(
    "h"));    //testStr是否以h開頭
            
            logger.debug(testStr.startsWith(
    "w"7));    //testStr從第七個字符開始的子串是否以w開頭
            
            logger.debug(testStr.endsWith(
    "/"));    //testStr是否以/結尾
            
            
    //replace首個參數均為regex正則
            logger.debug(testStr.replace("wap""www"));    //替換掉testStr所有的wap為www
            
            logger.debug(testStr.replaceAll(
    "\\w""T"));    //替換所有單個字符為T,\w 單獨字符 [a-zA-Z_0-9]
            
            logger.debug(testStr.replaceFirst(
    "w""R"));    //替換掉testStr中第一個w為R
            
            String arr[] 
    = testStr.split("\\.");    //按照指定正則來分隔testStr。api:split(String regex)
            for (String a: arr) {
                logger.debug(a);
            }

            
            logger.debug(testStr.substring(
    7));
            
            logger.debug(testStr.substring(
    1117));    //左包含
            
            logger.debug(testStr.toUpperCase());    
    //toLowerCase();
            
            logger.debug(
    "500wan".matches("\\w+"));        //true
            
            logger.debug(testStr.lastIndexOf(
    "0"));        //反向開始0出現的位置
            
            logger.debug(testStr.lastIndexOf(
    "0"10));        //反向10個字符開始,0出現的個數    
        }

    }

    //    [DEBUG      0  -line:15  -content:http://wap.500wan.com/
    //    [DEBUG      0  -line:17  -content:h
    //    [DEBUG     15  -line:19  -content:18
    //    [DEBUG     15  -line:21  -content:http://wap.500wan.com/trade/
    //    [DEBUG     15  -line:23  -content:8
    //    [DEBUG     47  -line:25  -content:9
    //    [DEBUG     47  -line:27  -content:5
    //    [DEBUG     47  -line:29  -content:true
    //    [DEBUG     47  -line:31  -content:true
    //    [DEBUG     47  -line:33  -content:true
    //    [DEBUG     47  -line:35  -content:http://www.500wan.com/
    //    [DEBUG     47  -line:37  -content:TTTT://TTT.TTTTTT.TTT/
    //    [DEBUG     47  -line:39  -content:http://Rap.500wan.com/
    //    [DEBUG     47  -line:43  -content:http://wap
    //    [DEBUG     47  -line:43  -content:500wan
    //    [DEBUG     47  -line:43  -content:com/
    //    [DEBUG     47  -line:46  -content:wap.500wan.com/
    //    [DEBUG     47  -line:48  -content:500wan
    //    [DEBUG     47  -line:50  -content:HTTP://WAP.500WAN.COM/
    //    [DEBUG     62  -line:52  -content:true
    //    [DEBUG     62  -line:54  -content:13
    //    [DEBUG     62  -line:56  -content:-1

    主站蜘蛛池模板: 亚洲V无码一区二区三区四区观看 亚洲αv久久久噜噜噜噜噜 | 亚洲成AV人片在线观看WWW| 美女被羞羞网站免费下载| 成人毛片18女人毛片免费96| 亚洲国产av美女网站| 亚洲视频免费在线播放| 久久久久亚洲av无码专区| 精品免费久久久久久久| 亚洲国产精品成人综合色在线婷婷| 222www在线观看免费| 亚洲国产成人精品青青草原| 免费人成在线视频| 亚洲av中文无码字幕色不卡| 免费萌白酱国产一区二区| 一区二区免费在线观看| ZZIJZZIJ亚洲日本少妇JIZJIZ| 新最免费影视大全在线播放| 亚洲中文字幕无码不卡电影| 亚欧免费无码aⅴ在线观看| 亚洲人成电影网站| 免费被黄网站在观看| 一级毛片免费不卡直观看| 亚洲乱码中文字幕综合| 无码av免费网站| 色偷偷亚洲女人天堂观看欧| 国产精品自在自线免费观看| a高清免费毛片久久| 精品日韩亚洲AV无码一区二区三区| 麻豆一区二区免费播放网站| 亚洲AV无码男人的天堂| 亚洲欧洲精品无码AV| 99久久精品日本一区二区免费| 亚洲av永久无码精品网址| 在线A亚洲老鸭窝天堂| av免费不卡国产观看| 深夜福利在线免费观看| 亚洲影院在线观看| 国产猛烈高潮尖叫视频免费| 182tv免费视频在线观看| 亚洲第一成人在线| 亚洲精品国产精品乱码不卡√ |