我正在尝试在 codenameone 函数中使用 replaceFirst(String,String) 并且出现此编译错误
/Users/jamesagada/ziemozi/Ziemozi/src/com/ixzdore/restdb/ziemview/FieldWatcher.java:130: error: cannot find symbol
result = result.replaceFirst(regex, field);
symbol: method replaceFirst(String,String)
location: variable result of type String
我有什么选择?我正在尝试实现准系统模板系统,代码是替换模板变量。
StringUtil
通常有大部分需要的方法,但没有replaceFirst
像大多数人选择的那样replaceAll
。您可以相对轻松地将其实现为实用程序:
public static String replaceFirst(String s, String pattern, String replacement) {
int idx = s.indexOf(pattern);
return s.substring(0, idx) + replacement + s.substring(idx + pattern.length());
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句