Hello,
I have a code with me , just check it out. If it works for your then it will great
Code:
Public class RegexSpaceSplit {
Public static void hand(String[] args) {
ArrayList <String> test = new ArrayList <String>();
/ / Test cases 0
test = Cutting(" \ t \ n \ t");
System.out.System.out.println("Case 0");
for (String substring: test) {
System.out.System.out.println(substring);
}
/ / Test case 1
test = Cutting(" \" aaaa bbbb\" \" cc cc\" dd \"\"ee\ n\ tff \"gg\"\"hh\" ii ");
System.out.System.out.println("\ nCase 1 ");
for (String substring: test) {
System.out.System.out.println(substring);
}
/ / Test case 2
test = Cutting("aa bb bb \"cc cc\" dd\ tdd \"eee\" f g \"hh\" \"ii\"\"dd\" kk ");
System.out.System.out.println("\ nCase 2 ");
for (String substring: test) {
System.out.System.out.println(substring);
}
}
Public static ArrayList <String> Cutting(String arr2) {
String regtest = "([\"]{1}[\\S\\s &&[^(\")]]*[\"]{1})";
ArrayList <String> arr1s = getChainesSansGuillemets(
arr2, regtest);
ArrayList <String> chainesAvecGuillemets = getChainesAvecGuillemets(
arr2, regtest);
ArrayList <String> chde = new ArrayList <String>();
/ / Case 0
/ / The string is empty
if (arr2.trim().length() == 0)
return chde;
/ / Case 1
/ / The first string contains quotation marks
else if (arr2.trim().charAt(0) == '\"') {
arr1s.remove(0);
while ((chainesAvecGuillemets.size() > 0)
&& (arr1s.size() > 0)) {
chde.add(chainesAvecGuillemets.remove(0));
for (String s: splitSpace(arr1s.remove(0)))
chde.add(s);
}
}
ArrayList <String> chre = new ArrayList <String>();
while (match.find())
for (int i = 0; I <match.GroupCount(); I + +)
chre.add(match.group(i));
return chre;
}
Bookmarks