Here you can find the source of replace(String src, String prefix, String suffix, Map props)
Parameter | Description |
---|---|
src | a parameter |
prefix | a parameter |
suffix | a parameter |
props | a parameter |
public final static String replace(String src, String prefix, String suffix, Map props)
//package com.java2s; import java.util.Map; public class Main { /**// w w w . ja va2 s. c om * replace a symbol in a string; * * @param src * @param prefix * @param suffix * @param props * @return */ public final static String replace(String src, String prefix, String suffix, Map props) { int index1; int index2; int len1 = prefix.length(); int len2 = suffix.length(); StringBuffer sb = new StringBuffer(); index1 = src.indexOf(prefix); while (index1 >= 0) { sb.append(src.substring(0, index1)); src = src.substring(index1 + len1); if (src.startsWith(prefix)) { sb.append(prefix); break; } else { index2 = src.indexOf(suffix); if (index2 >= 0) { String t = src.substring(0, index2); Object o = props.get(t); String sp = (o == null ? "" : o.toString()); sb.append(sp); src = src.substring((index2 + len2)); index1 = src.indexOf(prefix); } else { sb.append(prefix); break; } } } sb.append(src); return new String(sb); } }