也许这是基础知识,但我对这件事情不熟悉。 我有一组令牌,我想用地图将俚语代币替换为正确的单词。我应该把这5000张地图放在我的java中
public static Map<String, String> replacements;
static {
replacements.put("07734","hello");
replacements.put("0day","software illegally obtained before it was released");
replacements.put("0noe","oh no");
replacements.put("0vr","over");
replacements.put("10q","thank you");
............
这是我替换所有令牌的代码,但我仍然会遇到一些错误。
for (Map.Entry<String, String> replacement : replacements.entrySet() ){
int start = sb.indexOf(replacement.getKey(),0);
while (start >= 0){
int end = start + replacement.getKey().length();
sb.replace(start, end, replacement.getValue());
start = sb.indexOf(replacement.getKey(), start + replacement.getValue().length());
}
}