【发布时间】:2017-05-11 12:26:02
【问题描述】:
假设这些是一些 URL,
http://www.example.com/conditions/redirecting/home/ovc-20197858
http://www.example.com/conditions/gotos/definition/sys/ovc-20197858
现在我想用 place-for-you 替换 url 的单词 home 如果 url 包含 home 和 definition 与 如果 url 包含 定义,则放置。为此我写了一个代码,但它没有改变网址。
String newurl = "";
String url = "http://www.example.com/conditions/redirecting/home/ovc-20197858";
String home = "home";
String definition = "definition";
boolean check = url.matches("home");
// already tried boolean check = url.contains("home");
if(check == true)
{
newurl = url.replace(home,"place-for-you");
}
else
{
newurl = url.replace(definition,"place");
}
【问题讨论】: