【发布时间】:2014-12-04 12:34:26
【问题描述】:
给定两个字符串,base 和 remove,返回基本字符串的一个版本,其中删除字符串的所有实例都已被删除(不区分大小写)。您可以假设删除字符串的长度为 1 或更长。仅删除不重叠的实例,因此使用“xxx”删除“xx”会留下“x”。
withoutString("Hello there", "llo") → "He there"
withoutString("Hello there", "e") → "Hllo thr"
withoutString("Hello there", "x") → "Hello there"
为什么我不能使用这个代码:
public String withoutString(String base, String remove)
{
base.replace(remove, "");
return base;
}
【问题讨论】:
-
我没明白,为什么人们要投票给这个问题..:P