任何人都可以帮我解决如何从特殊字符中检索州名。我在下面提到了代码
字符串
[["<Select>"],["Andaman and Nicobar"],["Andhra Pradesh"],["Arunachal Pradesh"],["Assam"],["Bihar"],["Chandigarh"],["Chattishgarh"],["CHO Region"],["Dadra & Nagar Haveli"],["Daman & Diu"],["Goa"],["Gujarat"],["Haryana"],["Himachal Pradesh"],["Jammu and Kashmir"],["Jharkhand"],["Karnataka"],["Karnataka Chit"],["Kerala"],["Lakshadweep"],["Madhya Pradesh"],["Maharashtra"],["Maharashtra Chit"],["Manipur"],["Meghalaya"],["Mizoram"],["Nagaland"],["New Delhi"],["NORTH"],["Orissa"],["Pondichery"],["Punjab"],["Rajasthan"],["Sikkim"],["Tamil Nadu"],["Tripura"],["Uttar Pradesh"],["Uttaranchal"],["WEST"],["West Bengal"],null]
预期输出
<Select>,Andaman and Nicobar,Andhra Pradesh,Arunachal Pradesh,Assam,Bihar,Chandigarh,Chattishgarh,CHO Regio,Dadra & Nagar Haveli,Daman & Diu,Goa,Gujarat,Haryana,Himachal Pradesh,Jammu and Kashmir,Jharkhand,Karnataka,Karnataka Chit,Kerala,Lakshadweep,Madhya Pradesh,Maharashtra,Maharashtra Chit,Manipur,Meghalaya,Mizoram,Nagaland,New Delhi,NORTH,Orissa,Pondichery,Punjab,Rajasthan,Sikkim,Tamil Nadu,Tripura,Uttar Pradesh,Uttaranchal,WEST,West Bengal,null
答案 0 :(得分:1)
您可以使用以下代码
states = states.replace("[","").replace("]","").replace("\"", "");
答案 1 :(得分:0)
你可以通过删除括号来获得输出。 例如
String input = "[[\"<Select>\"],[\"Andaman and Nicobar\"],[\"Andhra Pradesh\"],[\"Arunachal Pradesh\"],[\"Assam\"],[\"Bihar\"],[\"Chandigarh\"],[\"Chattishgarh\"],[\"CHO Region\"],[\"Dadra & Nagar Haveli\"],[\"Daman & Diu\"],[\"Goa\"],[\"Gujarat\"],[\"Haryana\"],[\"Himachal Pradesh\"],[\"Jammu and Kashmir\"],[\"Jharkhand\"],[\"Karnataka\"],[\"Karnataka Chit\"],[\"Kerala\"],[\"Lakshadweep\"],[\"Madhya Pradesh\"],[\"Maharashtra\"],[\"Maharashtra Chit\"],[\"Manipur\"],[\"Meghalaya\"],[\"Mizoram\"],[\"Nagaland\"],[\"New Delhi\"],[\"NORTH\"],[\"Orissa\"],[\"Pondichery\"],[\"Punjab\"],[\"Rajasthan\"],[\"Sikkim\"],[\"Tamil Nadu\"],[\"Tripura\"],[\"Uttar Pradesh\"],[\"Uttaranchal\"],[\"WEST\"],[\"West Bengal\"],null]";
String output1 = input.replace("[", "");
String output2 = output1.replace("]", "");
System.out.println("output :"+output2);
此代码的输出
output :"<Select>","Andaman and Nicobar","Andhra Pradesh","Arunachal Pradesh","Assam","Bihar","Chandigarh","Chattishgarh","CHO Region","Dadra & Nagar Haveli","Daman & Diu","Goa","Gujarat","Haryana","Himachal Pradesh","Jammu and Kashmir","Jharkhand","Karnataka","Karnataka Chit","Kerala","Lakshadweep","Madhya Pradesh","Maharashtra","Maharashtra Chit","Manipur","Meghalaya","Mizoram","Nagaland","New Delhi","NORTH","Orissa","Pondichery","Punjab","Rajasthan","Sikkim","Tamil Nadu","Tripura","Uttar Pradesh","Uttaranchal","WEST","West Bengal",null
答案 2 :(得分:0)
您可以使用模式:
StringBuilder myFinalString = new StringBuilder();
String myString = "[[\"<Select>\"],[\"Andaman and Nicobar\"],[\"Andhra Pradesh\"],[\"Arunachal Pradesh\"],[\"Assam\"],[\"Bihar\"],[\"Chandigarh\"],[\"Chattishgarh\"],[\"CHO Region\"],[\"Dadra & Nagar Haveli\"],[\"Daman & Diu\"],[\"Goa\"],[\"Gujarat\"],[\"Haryana\"],[\"Himachal Pradesh\"],[\"Jammu and Kashmir\"],[\"Jharkhand\"],[\"Karnataka\"],[\"Karnataka Chit\"],[\"Kerala\"],[\"Lakshadweep\"],[\"Madhya Pradesh\"],[\"Maharashtra\"],[\"Maharashtra Chit\"],[\"Manipur\"],[\"Meghalaya\"],[\"Mizoram\"],[\"Nagaland\"],[\"New Delhi\"],[\"NORTH\"],[\"Orissa\"],[\"Pondichery\"],[\"Punjab\"],[\"Rajasthan\"],[\"Sikkim\"],[\"Tamil Nadu\"],[\"Tripura\"],[\"Uttar Pradesh\"],[\"Uttaranchal\"],[\"WEST\"],[\"West Bengal\"],null]";
Pattern stringPattern = Pattern.compile("\"[^\"]*\"|null");
Matcher matcher = stringPattern.matcher(myString);
while(matcher.find()) {
myFinalString.append(',').append(matcher.group());
}
System.out.println(myFinalString.toString().substring(1));