我想替换一个字符串表达式,并且收到此错误消息
error: cannot find symbol
test1 = testw.replaceAll("/uploads","http://www.anbariloche.com.ar/uploads");
symbol: method replaceAll(String,String)
location: variable testw of type String
这是我的代码
String testw= String.valueOf(element1);
String test1;
test1 = testw.replaceAll("/uploads","http://www.anbariloche.com.ar/uploads");
我使用Netbeans 8.1
Product Version: NetBeans IDE 8.1 (Build 201510222201)
Java: 1.7.0_79; Java HotSpot(TM) Client VM 24.79-b02
Runtime: Java(TM) SE Runtime Environment 1.7.0_79-b15
System: Windows 7 version 6.1 running on x86; Cp1252; es_ES (nb)
完整的代码已更新
@Override
protected void beforePortada(Form f) {
WebBrowser browser=new WebBrowser();
f.setLayout(new BorderLayout());
f.addComponent(BorderLayout.CENTER, browser);
/////Parse
String URL= "http://www.anbariloche.com.ar/";
ConnectionRequest req = new ConnectionRequest();
req.setUrl(URL);
NetworkManager.getInstance().addToQueueAndWait(req);
byte[] data = req.getResponseData();
if (data == null) {
}
XMLParser xmlParser=new XMLParser();
Element element= null;
try {
element = xmlParser.parse(new InputStreamReader(new ByteArrayInputStream(data), "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
Element element1=element.getChildAt(0);
String testw= String.valueOf(element1);
///replace the string
testw = testw.replaceAll("/uploads/","http://www.anbariloche.com.ar/uploads/");
browser.setPage(testw,null);
}
}
那是更新的代码,我可以看到我的错误在哪里
用弦
最佳答案
使用StringUtil.replaceAll(string, pattern, replace)。
要以真正的可移植方式在VM层中实现此任务要困难得多,因此,我们将您带向更可移植的版本。