String str="[[{TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=tesss}]]";
怎么把这个字符串转化成一个list。只要“=”号后面的就行
谢谢
24 个解决方案
#1
先用split(",")分隔放到一个数组
再对数组中的每个字符串从第一个"="截取到第一个"}"
最后转化成list
再对数组中的每个字符串从第一个"="截取到第一个"}"
最后转化成list
#2
import java.util.ArrayList;
public class SplitString{
public static void main(String[]args){
String str="[[{TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=tesss}]]";
String[]strs=str.split(",");
ArrayList<String> strList=new ArrayList<String>();
for(int i=0;i<strs.length;i++){
strList.add(strs[i].substring(strs[i].indexOf("=")+1,strs[i].indexOf("}")));
}
for(int i=0;i<strList.size();i++){
System.out.println(strList.get(i));
}
}
}
#3
List<String> listOfDates = Arrays.asList(yourArray);
#4
#5
对的
#6
+1
#7
测了也下!正解!
import java.util.ArrayList;
public class TT {
public static void main(String args[]){
String str="[[{TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=tesss}]]";
String[]strs=str.split(",");
ArrayList<String> strList=new ArrayList<String>();
for(int i=0;i<strs.length;i++){
strList.add(strs[i].substring(strs[i].indexOf("=")+1,strs[i].indexOf("}")));
}
for(int i=0;i<strList.size();i++){
System.out.println(strList.get(i));
}
}
}
#8
+1
#9
#10
可以考虑用正则
String str="[[{TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=tesss}]]";
String reg = "\\=.*?\\}"; //取=和}之间的内容
Pattern p = Pattern.compile(reg);
Matcher m = p.matcher(str);
List<String> list = new ArrayList<String>();
while (m.find()) {
String s = m.group();
list.add(s.substring(1,s.length()-1)); //把=和}去掉
}
System.out.println(Arrays.toString(list.toArray(new String[0])));
#11
10楼的看着简单点
#12
public static void main(String[] args)
{
String str = "[[{TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=tesss}]]";
String [] s =str.replace("[[", "").replace("]]", "").split(",");
List<String> list=new ArrayList<String>();
for(String m:s)
{
System.out.println(m.substring(m.indexOf("=")+1,m.length()-1));
list.add(m.substring(m.indexOf("=")+1,m.length()-1));
}
}
{
String str = "[[{TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=tesss}]]";
String [] s =str.replace("[[", "").replace("]]", "").split(",");
List<String> list=new ArrayList<String>();
for(String m:s)
{
System.out.println(m.substring(m.indexOf("=")+1,m.length()-1));
list.add(m.substring(m.indexOf("=")+1,m.length()-1));
}
}
#13
赞一个。
#14
public static void main(String[] args)
{
String str = "[[{TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=tesss}]]";
String [] s =str.replace("[[", "").replace("]]", "").replace("{TYPE_SIZE=", "").replace("}", "").split(",");
List<String> list= Arrays.asList(s);
}
#15
你这是json 封装的数据, 你用json将其转换一下就好了
要是对json不懂,可以找google 和看相关文档
要是对json不懂,可以找google 和看相关文档
#16
这个问题你要好好看看java.lang.String中的方法了。。。
#17
java没有提供这样的方法,自己写
#18
public static void main(String[] args)
{
String str = "[[{TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=tesss}]]";
String [] s =str.replace("[[", "").replace("]]", "").split(",");
List<String> list=new ArrayList<String>();
for(String m:s)
{
System.out.println(m.substring(m.indexOf("=")+1,m.length()-1));
list.add(m.substring(m.indexOf("=")+1,m.length()-1));
}
}
{
String str = "[[{TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=tesss}]]";
String [] s =str.replace("[[", "").replace("]]", "").split(",");
List<String> list=new ArrayList<String>();
for(String m:s)
{
System.out.println(m.substring(m.indexOf("=")+1,m.length()-1));
list.add(m.substring(m.indexOf("=")+1,m.length()-1));
}
}
#19
+1
#20
我和14楼的想法是一样的。
先替换再转换 这样简单一点
#21
我的建议是使用分割,其他正则我不会
#22
kkk
#23
上面的这两种方法虽然都实现了,可觉得效率都不好
#24
把开头的"[[{TYPE_SIZE="删掉,把结尾的"}]]"删掉
然后用split("}, {TYPE_SIZE=")分割
然后用split("}, {TYPE_SIZE=")分割
#1
先用split(",")分隔放到一个数组
再对数组中的每个字符串从第一个"="截取到第一个"}"
最后转化成list
再对数组中的每个字符串从第一个"="截取到第一个"}"
最后转化成list
#2
import java.util.ArrayList;
public class SplitString{
public static void main(String[]args){
String str="[[{TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=tesss}]]";
String[]strs=str.split(",");
ArrayList<String> strList=new ArrayList<String>();
for(int i=0;i<strs.length;i++){
strList.add(strs[i].substring(strs[i].indexOf("=")+1,strs[i].indexOf("}")));
}
for(int i=0;i<strList.size();i++){
System.out.println(strList.get(i));
}
}
}
#3
List<String> listOfDates = Arrays.asList(yourArray);
#4
#5
对的
#6
+1
#7
测了也下!正解!
import java.util.ArrayList;
public class TT {
public static void main(String args[]){
String str="[[{TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=tesss}]]";
String[]strs=str.split(",");
ArrayList<String> strList=new ArrayList<String>();
for(int i=0;i<strs.length;i++){
strList.add(strs[i].substring(strs[i].indexOf("=")+1,strs[i].indexOf("}")));
}
for(int i=0;i<strList.size();i++){
System.out.println(strList.get(i));
}
}
}
#8
+1
#9
#10
可以考虑用正则
String str="[[{TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=tesss}]]";
String reg = "\\=.*?\\}"; //取=和}之间的内容
Pattern p = Pattern.compile(reg);
Matcher m = p.matcher(str);
List<String> list = new ArrayList<String>();
while (m.find()) {
String s = m.group();
list.add(s.substring(1,s.length()-1)); //把=和}去掉
}
System.out.println(Arrays.toString(list.toArray(new String[0])));
#11
10楼的看着简单点
#12
public static void main(String[] args)
{
String str = "[[{TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=tesss}]]";
String [] s =str.replace("[[", "").replace("]]", "").split(",");
List<String> list=new ArrayList<String>();
for(String m:s)
{
System.out.println(m.substring(m.indexOf("=")+1,m.length()-1));
list.add(m.substring(m.indexOf("=")+1,m.length()-1));
}
}
{
String str = "[[{TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=tesss}]]";
String [] s =str.replace("[[", "").replace("]]", "").split(",");
List<String> list=new ArrayList<String>();
for(String m:s)
{
System.out.println(m.substring(m.indexOf("=")+1,m.length()-1));
list.add(m.substring(m.indexOf("=")+1,m.length()-1));
}
}
#13
赞一个。
#14
public static void main(String[] args)
{
String str = "[[{TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=tesss}]]";
String [] s =str.replace("[[", "").replace("]]", "").replace("{TYPE_SIZE=", "").replace("}", "").split(",");
List<String> list= Arrays.asList(s);
}
#15
你这是json 封装的数据, 你用json将其转换一下就好了
要是对json不懂,可以找google 和看相关文档
要是对json不懂,可以找google 和看相关文档
#16
这个问题你要好好看看java.lang.String中的方法了。。。
#17
java没有提供这样的方法,自己写
#18
public static void main(String[] args)
{
String str = "[[{TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=tesss}]]";
String [] s =str.replace("[[", "").replace("]]", "").split(",");
List<String> list=new ArrayList<String>();
for(String m:s)
{
System.out.println(m.substring(m.indexOf("=")+1,m.length()-1));
list.add(m.substring(m.indexOf("=")+1,m.length()-1));
}
}
{
String str = "[[{TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=tesss}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=typesize}, {TYPE_SIZE=tesss}]]";
String [] s =str.replace("[[", "").replace("]]", "").split(",");
List<String> list=new ArrayList<String>();
for(String m:s)
{
System.out.println(m.substring(m.indexOf("=")+1,m.length()-1));
list.add(m.substring(m.indexOf("=")+1,m.length()-1));
}
}
#19
+1
#20
我和14楼的想法是一样的。
先替换再转换 这样简单一点
#21
我的建议是使用分割,其他正则我不会
#22
kkk
#23
上面的这两种方法虽然都实现了,可觉得效率都不好
#24
把开头的"[[{TYPE_SIZE="删掉,把结尾的"}]]"删掉
然后用split("}, {TYPE_SIZE=")分割
然后用split("}, {TYPE_SIZE=")分割