Java Regex String Replace replace(String operateOn[], String from, String to)

Here you can find the source of replace(String operateOn[], String from, String to)

Description

Iterates over the items in operateOn and replaces any matches of from to to.

License

Open Source License

Parameter

Parameter Description
operateOn the operate on
from the from
to the to

Declaration

public static void replace(String operateOn[], String from, String to) 

Method Source Code

//package com.java2s;
/*/*  www.j ava2s . c  o m*/
  DA-NRW Software Suite | ContentBroker
  Copyright (C) 2013 Historisch-Kulturwissenschaftliche Informationsverarbeitung
  Universit?t zu K?ln
    
  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.
    
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
    
  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    /**
     * Iterates over the items in operateOn and replaces any matches
     * of from to to.
     *
     * @param operateOn the operate on
     * @param from the from
     * @param to the to
     * @author Daniel M. de Oliveira
     */
    public static void replace(String operateOn[], String from, String to) {
        for (int i = 0; i < operateOn.length; i++) {

            Pattern patternOutput = Pattern.compile(from);
            Matcher matcherOutput = patternOutput.matcher(operateOn[i]);
            operateOn[i] = matcherOutput.replaceFirst(to);
        }
    }
}

Related

  1. replace(String input, Pattern regex, Function converter)
  2. replace(String inputStr, String patternStr, String replacementStr)
  3. replace(String inString, String oldPattern, String newPattern)
  4. replace(String line, String regexp, String replacement)
  5. replace(String message, ResourceBundle bundle)
  6. replace(String original, CharSequence target, CharSequence replacement)
  7. replace(String pattern, String replace, String s)
  8. replace(String s, Pattern pattern, Function func)
  9. replace(String s, Properties p)