One solution could be to split input and read only odd index.
public class Split {
public static void main(String[] args)
{
String sin = "Today is a \"nice day\" and i \"like\" it because because of the \"sun and flowers\".";
System.out.println(sin);
String[] s=sin.split("\"");
for(int i=0;i<s.length;i++)
if(i%2==1) System.out.println(s[i]);
}
}
Output:
Today is a "nice day" and i "like" it because because of the "sun and flowers".
nice day
like
sun and flowers
Update on posted code:
public class Split {
public static void main(String[] args)
{
String sin = "Today is a \"nice day\" and i \"like\" it because because of the \"sun and flowers\".";
String sout = Split.getStringBetweenTwoChars(sin, "\"", "\"");
System.out.println(sout);
}
public static String getStringBetweenTwoChars(String input, String startChar, String endChar) {
try {
for (int i = 0; i < input.length(); i++) {
System.out.println("Input-Length: " + input.length());
int start = input.indexOf(startChar);
if (start != -1) {
int end = input.indexOf(endChar, start + startChar.length());
System.out.println("Das sind: " + end);
if (end != -1) {
String x = input.substring(start + startChar.length(), end);
input = input.substring(end + 1);
System.out.println("RestText: "+input);
System.out.println("QuoteText: "+x);
String snext=getStringBetweenTwoChars(input, "\"", "\"");
if(snext!=null)
x=x+","+snext;
return x;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
Output
Today is a "nice day" and i "like" it because because of the "sun and flowers".
Input-Length: 79
Das sind: 20
RestText: and i "like" it because because of the "sun and flowers".
QuoteText: nice day
Input-Length: 58
Das sind: 12
RestText: it because because of the "sun and flowers".
QuoteText: like
Input-Length: 45
Das sind: 43
RestText: .
QuoteText: sun and flowers
Input-Length: 1
nice day,like,sun and flowers
Update for array
//let method signature as it is
String sout = Split.getStringBetweenTwoChars(sin, "\"", "\"");
//remove comma and get result into array
String[] s=sout.split(",");