JAVA正则表达式双引号问题
privateString[]mid={"whilenow","people","humans"};上面的字符串如何用正则表达式转换为privateString[]mid...
private String[] mid = {"whilenow","people","humans"};
上面的字符串如何用正则表达式转换为private String[] mid = {<span class="character">“whilenow”</span>,<span class="character">"people"</span>,<span class="character">"humans"</span>};
如果引号的数量不止3个呢,可以不用正则表达式
只是要求把双引号及其里面的内容转换为<span class="character">“引号内容”</span> 展开
上面的字符串如何用正则表达式转换为private String[] mid = {<span class="character">“whilenow”</span>,<span class="character">"people"</span>,<span class="character">"humans"</span>};
如果引号的数量不止3个呢,可以不用正则表达式
只是要求把双引号及其里面的内容转换为<span class="character">“引号内容”</span> 展开
3个回答
展开全部
能不能不用正则表达式。。。你可以写个方法把<span class="character">和</span>抽离出来撒,然后把这个数组private String[] mid = {"whilenow","people","humans"};里面的元素按参数传递进去。。。字符串拼接的方式放回字符串数组啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
String[] mid = {"whilenow", "people", "humans"};
System.out.println(Arrays.toString(mid));
for(int i = 0; i < mid.length; ++i) {
mid[i] = String.format("<span class=\"character\">\"%s\"</span>",mid[i]);
}
System.out.println(Arrays.toString(mid));
[whilenow, people, humans]
[<span class="character">"whilenow"</span>, <span class="character">"people"</span>, <span class="character">"humans"</span>]
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
String s ="private String[] mid = {\"whilenow\",\"people\",\"humans\"};";
System.out.println(s.replaceAll("\"\\w+\"", "<span class=\"character\">$0</span>"));
这样可以
System.out.println(s.replaceAll("\"\\w+\"", "<span class=\"character\">$0</span>"));
这样可以
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询