stringutil.java

来自「这个是一个牛人写的分页标签」· Java 代码 · 共 41 行

JAVA
41
字号
package net.xdevelop.util;/** * <p>Title: 字符串工具类</p> * @author from jive * @version 1.0 */public class StringUtil {    /**     * Replaces all instances of oldString with newString in line.     * @param line the String to search to perform replacements on     * @param oldString the String that should be replaced by newString     * @param newString the String that will replace all instances of oldString     * @return a String will all instances of oldString replaced by newString     */    public static final String replace( String line, String oldString, String newString )    {        if (line == null) {            return null;        }        int i=0;        if ( ( i=line.indexOf( oldString, i ) ) >= 0 ) {            char [] line2 = line.toCharArray();            char [] newString2 = newString.toCharArray();            int oLength = oldString.length();            StringBuffer buf = new StringBuffer(line2.length);            buf.append(line2, 0, i).append(newString2);            i += oLength;            int j = i;            while( ( i=line.indexOf( oldString, i ) ) > 0 ) {                buf.append(line2, j, i-j).append(newString2);                i += oLength;                j = i;            }            buf.append(line2, j, line2.length - j);            return buf.toString();        }        return line;    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?