Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static String stringReplace(String str, String what, String replacement) {
        int i = str.indexOf(what);

        if (i >= 0) {
            int j = 0;
            int whatLen = what.length();
            StringBuilder result = new StringBuilder();

            do {
                result.append(str.substring(j, i));
                result.append(replacement);

                j = i + whatLen;
                i = str.indexOf(what, j);
            } while (i >= 0);

            result.append(str.substring(j));

            return result.toString();
        } else {
            return str;
        }
    }
}