码迷,mamicode.com
首页 > 其他好文 > 详细

Utils

时间:2017-09-11 15:18:58      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:length   stat   replace   into   col   val   ati   util   src   

public static String[] splitBySeparator(String source, String separator) {
        int startIndex = 0;
        int endIndex = source.indexOf(separator);
        Vector vector = new Vector();
        for (; endIndex >= startIndex; endIndex = source.indexOf(separator, startIndex)) {
            vector.add(source.substring(startIndex, endIndex));
            startIndex = endIndex + separator.length();
        }

        vector.add(source.substring(startIndex));
        String returnValue[] = new String[vector.size()];
        vector.copyInto(returnValue);
        return returnValue;
    }

 

public static String replaceAll(String src, String tarStr, String repStr) {

        int srcPos = 0;
        int tarPos = 0;
        StringBuffer result = new StringBuffer(25);
        while ((tarPos = src.indexOf(tarStr, srcPos)) >= 0) {
            result.append(src.substring(srcPos, tarPos));
            result.append(repStr);
            srcPos = tarPos + tarStr.length();
        }
        result.append(src.substring(srcPos));
        String finalString = result.toString();
        return finalString;
    }

 

Utils

标签:length   stat   replace   into   col   val   ati   util   src   

原文地址:http://www.cnblogs.com/jingRegina/p/7504878.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!