<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

    主站蜘蛛池模板: 最近最好最新2019中文字幕免费| 亚洲AV无码AV日韩AV网站| 久久99精品免费一区二区| 国产免费卡一卡三卡乱码| 亚洲暴爽av人人爽日日碰| 日韩a在线观看免费观看| 国产精品亚洲专区无码WEB| 日本久久久免费高清| 免费国产黄网站在线观看动图 | 日本高清免费观看| 亚洲国产成人精品不卡青青草原| 久久青草91免费观看| 亚洲视频在线观看不卡| 无限动漫网在线观看免费| 亚洲狠狠婷婷综合久久| 亚洲成a人片在线观看久| 久久免费观看视频| 78成人精品电影在线播放日韩精品电影一区亚洲 | 四虎在线免费视频| 亚洲精品自偷自拍无码| 亚洲?v女人的天堂在线观看| 精品一区二区三区高清免费观看| 久久精品亚洲综合| 两个人的视频高清在线观看免费 | 国产产在线精品亚洲AAVV| 国产啪亚洲国产精品无码| 免费女人高潮流视频在线观看| 亚洲AV无码乱码在线观看代蜜桃| 永久中文字幕免费视频网站| 国产黄色免费观看| 亚洲国产日韩在线人成下载| 亚洲AV之男人的天堂| 久99久精品免费视频热77| 亚洲熟伦熟女专区hd高清| 亚洲午夜精品久久久久久浪潮 | 亚洲欧洲另类春色校园网站| 亚洲精品成人久久久| 99re在线这里只有精品免费| 亚洲日韩在线中文字幕综合 | 日韩免费在线中文字幕| 亚洲精品美女久久久久9999|