You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
40 lines
1.1 KiB
package com.fr.design.mod; |
|
|
|
import java.util.regex.Matcher; |
|
import java.util.regex.Pattern; |
|
|
|
/** |
|
* @author hades |
|
* @version 10.0 |
|
* Created by hades on 2021/5/31 |
|
*/ |
|
public class ContentReplaceUtil { |
|
|
|
public static final String EQ_STRING = "="; |
|
|
|
public static String replaceContent(String content, String oldName, String newName) { |
|
String oldNameUpper = oldName.toUpperCase(); |
|
Matcher m = Pattern.compile(oldName + "|" + oldNameUpper).matcher(content); |
|
StringBuilder sb = new StringBuilder(); |
|
int last = 0; |
|
while (m.find()) { |
|
sb.append(content, last, m.start()); |
|
if (oldNameUpper.equals(m.group())) { |
|
// 处理大写情况 |
|
sb.append(newName.toUpperCase()); |
|
} else { |
|
// 默认情况 |
|
sb.append(newName); |
|
} |
|
last = m.end(); |
|
} |
|
sb.append(content.substring(last)); |
|
|
|
return sb.toString(); |
|
} |
|
|
|
private static String generateStr(String str) { |
|
return "\"" + str + "\""; |
|
} |
|
|
|
}
|
|
|