0

I have a String(freeText) "Manas \"Jaikant IBM\"". I want to split into two strings:

String normalMatch="Manas";
String exactMatch="Jaikant IBM";

It means that String normalMatch contains Manas and String exactMatch contains Jaikant IBM.

i am using the split() method of String class in Java

String[] splittedText= freeText.split("\\s");

I am getting 3 string elements but i need 2 string elements only.

  • Also see [this](http://stackoverflow.com/questions/10695143/split-a-quoted-string-with-a-delimiter). – devnull Feb 02 '14 at 07:14

2 Answers2

0

Use substring instead of split:

int index = freeText.indexOf(" ");
String normalMatch = freeText.substring(0,index);
String exactMatch  = freeText.substring(index); // endIndex == freeText.length())
barak manos
  • 29,648
  • 10
  • 62
  • 114
0

Split on quotes(") then, you will get Manas and Jaikant IBM and can ignore the 3rd value.

Vivek Vermani
  • 1,934
  • 18
  • 45