- 我的输入t%60hiag%2Fra%2Cjan
- 我希望将其转换为 t%60hiag%2fra%2cjan
我想用 %2f 替换 %2F。即 0-9 之间的任何数字后跟 A-F 的大写字母都应转换为小写字母。
我能够提取并替换为通用字符串。但我需要帮助将提取的字符串替换为小写。
private static String urlEncodeLowerCase(String stringInput)
{
stringInput = stringInput.replaceAll("%[0-9]{1}[A-F]{1}", "T");
return stringInput;
}
上面的代码将提取并用“T”替换提取的字符串,但我想要类似的东西
stringInput = stringInput.replaceAll("%[0-9]{1}[A-F]{1}", "%[0-9]{1}[A-Z]{1}".toLowerCase);
上面的代码不起作用。这只是为了让您了解我的要求。
最佳答案
试试这个
private static String urlEncodeLowerCase(String stringInput) {
Pattern pattern = Pattern.compile("%[0-9]{1}[A-Z]{1}");
Matcher matcher = pattern.matcher(stringInput);
while (matcher.find()) {
String s = matcher.group();
stringInput = stringInput.replace(s, s.toLowerCase());
}
return stringInput;
}
关于java - 如何提取字符串的特定部分并用相同的提取值替换,但在不同的情况下 - 使用java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52541290/