Java 在gwt 2.5.1中使用新行字符拆分字符串?
以下代码块在开发模式下可以正常工作,但当我部署到服务器时,它不能正常工作。无法使用新行字符拆分多行? 基本上,将多行字符串格式化为“,”分隔字符串标记 套餐:Java 在gwt 2.5.1中使用新行字符拆分字符串?,java,javascript,gwt,Java,Javascript,Gwt,以下代码块在开发模式下可以正常工作,但当我部署到服务器时,它不能正常工作。无法使用新行字符拆分多行? 基本上,将多行字符串格式化为“,”分隔字符串标记 套餐: import com.google.gwt.regexp.shared.RegExp; import com.google.gwt.regexp.shared.SplitResult; public void onSubmitComplete(SubmitCompleteEvent event) {
import com.google.gwt.regexp.shared.RegExp;
import com.google.gwt.regexp.shared.SplitResult;
public void onSubmitComplete(SubmitCompleteEvent event) {
String plateStr = "";
if(event.getResults() != null){
String uploadStr = event.getResults();
//Log.warn(this.getClass().getName() + " - event.getResults():"+ uploadStr);
RegExp regExp = RegExp.compile("\\r?\\n");
SplitResult sp = regExp.split(uploadStr);
Log.warn(this.getClass().getName() + " - sp.length():"+ sp.length() + ", SplitResult:"+ sp.toString());
for(int i = 0; i < sp.length() ; i++){
Log.warn(this.getClass().getName() + " - PlateLine["+ i+ "] - " + sp.get(i));
if(!sp.get(i).trim().isEmpty()){
RegExp regLine = RegExp.compile(",");
SplitResult spLine = regLine.split(sp.get(i));
for(int j = 0; j < spLine.length(); j++){
if(spLine.get(j) != null && !spLine.get(j).trim().isEmpty()){
plateStr = plateStr + "," + spLine.get(j);
}
}
}
}
//plateStr = Arrays.toString(lines).replace("[","").replace("]", "");
if(!plateStr.trim().isEmpty()){
plateStr = plateStr.substring(1,plateStr.length());
}
Log.warn(this.getClass().getName() + " - PlateString:"+ plateStr);
}
参考:
使用此代码对我有效。您是否尝试过使用
String.split(“\\r?\\n”)
?我没有尝试过,最初我尝试了String split,然后改为Regexp。最后我在服务器端处理了这个问题。很好,这是解决这个问题的正确地方。但我很惊讶为什么String.split(\\r?\\n”)
在客户端不起作用。
JsArrayString arrayString = splitString(uploadStr, "\n");
public static final native JsArrayString splitString(String string, String separator) /*-{
return string.split(separator);
}-*/;