Here you can find the source of replaceIgnoreCase(String source, String strBeReplace, String strReplaced)
public static String replaceIgnoreCase(String source, String strBeReplace, String strReplaced)
//package com.java2s; /* /*from ww w .j av a 2s . c o m*/ * @(#)StringUtil.java 1.0 2004-10-11 * * Copyright 2005 UFIDA Software Co. Ltd. All rights reserved. * UFIDA PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ import java.util.Iterator; public class Main { public static String replaceIgnoreCase(String source, String strBeReplace, String strReplaced) { if (isEmpty(source) || isEmpty(strBeReplace) || strReplaced == null) return source; StringBuffer buf = new StringBuffer(source.length()); int start = 0, end = 0; String strReplacedCopy = strBeReplace.toUpperCase(); String sourceCopy = source.toUpperCase(); while ((end = sourceCopy.indexOf(strReplacedCopy, start)) != -1) { buf.append(source.substring(start, end)).append(strReplaced); start = end + strReplacedCopy.length(); } buf.append(source.substring(start)); return buf.toString(); } public static boolean isEmpty(String str) { return str == null || str.length() == 0; } public static String toString(Object[] arr) { return toString(arr, ","); } @SuppressWarnings("unchecked") public static String toString(Object value, String delim) { if (value instanceof String) { return (String) value; } else { if (value.getClass().isArray()) { return toString((Object[]) value, delim); } else if (value instanceof Iterable) { return toString((Iterable) value, delim); } else { return value.toString(); } } } @SuppressWarnings("unchecked") public static String toString(Iterable c, String delim, String prefix, String suffix) { if (c == null) { return "null"; } StringBuffer sb = new StringBuffer(); Iterator it = c.iterator(); int i = 0; while (it.hasNext()) { if (i++ > 0) { sb.append(delim); } sb.append(prefix + it.next() + suffix); } return sb.toString(); } @SuppressWarnings("unchecked") public static String toString(Iterable c, String delim) { return toString(c, delim, "", ""); } public static String toString(Object value) { return toString(value, ","); } public static String toString(Object[] arr, String delim) { if (arr == null) { return "null"; } else { StringBuffer sb = new StringBuffer(); for (int i = 0; i < arr.length; i++) { if (i > 0) sb.append(delim); sb.append(arr[i]); } return sb.toString(); } } }