如何从数组获取数据到字符串JAVA?

时间:2017-03-28 13:21:59

标签: java

我有一个如下所示的数组:

ss="date:03/27/2017,text=sample,date:03/28/2017"

但是我希望将数组中的03/27/2017只放入一个字符串中 JAVA怎么可能?

2 个答案:

答案 0 :(得分:0)

您可以使用split方法,看看:

String ss="date:03/27/2017,text=sample,date:03/28/2017";
String date = ss.split(",")[2].split(":")[1];
System.out.println(date);//03/28/2017

步骤一步

ss.split(",");//[date:03/27/2017, text=sample, date:03/28/2017]
ss.split(",")[2];//date:03/28/2017
ss.split(",")[2].split(":");//[date, 03/28/2017]
ss.split(",")[2].split(":")[1];//03/28/2017

答案 1 :(得分:0)

尝试此操作以提取String中的每个日期,或者如果是数组,则可以将其转换为String,然后应用此模式以查找匹配项。

Pattern pattern = Pattern.compile("\\d{2}+/\\d{2}+/\\d{4}+");
String ss = "date:03/27/2017,text=sample,date:03/28/2017";
Matcher matcher = pattern.matcher(ss);
while(matcher.find()) {
     System.out.println(ss.substring(matcher.start(), matcher.end()));
}

希望这个帮助