Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Copyright 2012 sohu.com All right reserved. This software is the
 * confidential and proprietary information of sohu.com ("Confidential
 * Information"). You shall not disclose such Confidential Information and shall
 * use it only in accordance with the terms of the license agreement you entered
 * into with sohu.com.
 */

public class Main {
    public static void replaceAll(StringBuilder sb, String source, String target) {
        int index = 0;
        int endIndex = 0;
        int length = source.length();
        while (-1 != (index = sb.indexOf(source, index))) {
            endIndex = index + length;
            sb.replace(index, endIndex, target);
            index += target.length() + 5;
        }
    }

    public static void replace(StringBuilder sb, String source, String target) {
        int index = sb.indexOf(source);
        int endIndex = index + source.length();
        sb.replace(index, endIndex, target);
    }
}