![](https://iknow-base.cdn.bcebos.com/lxb/notice.png)
java字符串数组替换问题
Strings="407298a";String[]s1={"407298a"};System.out.println(s.eqauls(s1[0]));System.o...
String s="407298a";
String[] s1={"407298a"};
System.out.println(s.eqauls(s1[0]));
System.out.println(s1[0].replaceAll("a", ""));
System.out.println(s.replaceAll("a", ""));
运行结果
true
407298a
407298
为什么字符串数组s1[0]里面的a替换不掉呢 字符串数组的元素补还是字符串吗 而且s和s1[0]明明是相等的 展开
String[] s1={"407298a"};
System.out.println(s.eqauls(s1[0]));
System.out.println(s1[0].replaceAll("a", ""));
System.out.println(s.replaceAll("a", ""));
运行结果
true
407298a
407298
为什么字符串数组s1[0]里面的a替换不掉呢 字符串数组的元素补还是字符串吗 而且s和s1[0]明明是相等的 展开
2个回答
展开全部
@Test
public void TestReplace(){
String url = "www.asd.com/?userid={userid}&password={password}";
String[] values = {"123","321"};
String regex = "\\{[^\\{\\}]*\\}";
Pattern pt = Pattern.compile(regex);
Matcher match = pt.matcher(url);
int i = 0;
while(match.find()) {
String paramValue = match.group();
url = url.replaceAll(paramValue.replaceAll("\\{", "\\\\{").replaceAll("\\}", "\\\\}"), values[i]);
i++;
}
System.out.println("url ===="+url);
}
public void TestReplace(){
String url = "www.asd.com/?userid={userid}&password={password}";
String[] values = {"123","321"};
String regex = "\\{[^\\{\\}]*\\}";
Pattern pt = Pattern.compile(regex);
Matcher match = pt.matcher(url);
int i = 0;
while(match.find()) {
String paramValue = match.group();
url = url.replaceAll(paramValue.replaceAll("\\{", "\\\\{").replaceAll("\\}", "\\\\}"), values[i]);
i++;
}
System.out.println("url ===="+url);
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2016-05-17
展开全部
没有直接法,只能通过循环String[]ary={"abc","123","45"};StringBuffersb=newStringBuffer();for(inti=0;i
追问
什么意思? 我数组只有一个元素 直接提取出来了的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询