2012-08-25 114 views

回答

3

使用String#replace

String yourString = "This&aIs&aA&aTest"; 
yourString = yourString.replace("&a", ""); 
1

使用正则表达式用的replaceAll()

str.replaceAll("&a", ""); 
3

使用String.replace

s = s.replace("&a", ""); 

记住,字符串是不可变的。 String.replace实际上并未修改字符串。您需要将结果返回给变量。

看到它联机工作:ideone

-4

这正是String对象的替换功能是。如果你想获得一个&出现的所有,使用正则表达式,像这样:

<html> 
<script> 

a = "This&aIs&aA&aTest" 

alert(a.replace(new RegExp ("&a", "g") , " ")); 

</script> 
</html> 

或的replaceAll()。

+2

OP正在使用Java,而不是Javascript。 – Vulcan

+0

糟糕。这是。第三天在这个网站上。 Sowwy – Technologeeks

+0

你总是可以删除你的答案并获得回报:) – Pshemo