Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.StringTokenizer;

public class Main {
    public static String restoreWithEndnote(String text, String holderString, String replacement, String noteTag,
            String noteSplit) {
        int start = text.lastIndexOf(noteTag);
        String note = text.substring(start);
        text = text.substring(0, start);
        if (note.length() == noteTag.length())
            return text;
        StringBuilder sb = new StringBuilder(text);
        StringTokenizer token = new StringTokenizer(note.substring(1), noteSplit);
        int[] index = new int[token.countTokens()];
        for (int i = index.length - 1; i >= 0; i--) {
            index[i] = Integer.parseInt(token.nextToken());
        }

        int h_length = holderString.length();
        for (int i = 0; i < index.length; i++) {
            sb.replace(index[i], index[i] + h_length, replacement);
        }
        return sb.toString();
    }
}