Here you can find the source of replaceAll(String src, String[] replace, String[] by)
Parameter | Description |
---|---|
src | the string to replace values in |
replace | the substrings to find |
by | what to replace the substrings with |
public static String replaceAll(String src, String[] replace, String[] by)
//package com.java2s; //License from project: Open Source License import java.util.Arrays; public class Main { /**// w w w . j a v a 2 s . c om * Replaces all Strings in replace by the corresponding String in by, that * is the ith String in replace is replaced by the ith String in by, in * order. * * @param src the string to replace values in * @param replace the substrings to find * @param by what to replace the substrings with * @return the replaced string */ public static String replaceAll(String src, String[] replace, String[] by) { for (int i = 0; i < replace.length; i++) { src = src.replace(replace[i], by[i]); } return src; } /** * Replaces all Strings in replace by by. * * @param src the string to replace values in * @param replace the substrings to find * @param by what to replace the substrings with * @return the replaced string */ public static String replaceAll(String src, String[] replace, String by) { String[] rb = new String[replace.length]; Arrays.fill(rb, by); return replaceAll(src, replace, rb); } }