0

I have a string that might look like this:

searchText = search:kind:(reports) unit.id:(("CATS (WILLIAMS)"~1) OR ("DOGS (JAMES)"~1)) 

I need to extact any values that may exist in the quotation marks so in this case it would be:

CATS (WILLIAMS) and DOGS (JAMES)

Not sure I understand how using indexOf and subString will get me a text string since they depend on integer values... Can someone show me some examples of how this might be done? Thanks

Ok figured out the basics, but I need it to extract every value in " " not just the first instance. The below extacts the value then converts the name into an id then replaces the name with an id, but ONLY does the first instance.

       String unitIdStart = "\"";
       String unitIdEnd = "\"~";

       int unitIdStartIndex = searchText.indexOf(unitIdStart);
       if( unitIdStartIndex != -1 ) {
           int unitIdEndIndex = searchText.indexOf(unitIdEnd, unitIdStartIndex);
           if( unitIdEndIndex != -1 );
           {

               String unitName = searchText.substring(unitIdStartIndex+1, unitIdEndIndex);
               Unit backToId = UnitRepository.getIdFromName(unitName);
               String unitId = backToId.getId().toString();

               String searchTextWithUnitId = searchText.replace(unitName, unitId);
Jason
  • 754
  • 3
  • 8
  • 22
  • You use `indexOf` to retrieve the position of the borders (in your case the quotation marks). Then you can use `subString` to extract some text between the already retrieved border positions. Show us some code – Anton Sarov Dec 07 '15 at 22:09
  • 3
    The term you are looking for is regex. – John Dec 07 '15 at 22:09
  • See this: http://stackoverflow.com/questions/1473155/how-to-get-data-between-quotes-in-java AND http://stackoverflow.com/questions/14574689/extract-a-substring-between-double-quotes-with-regular-expression-in-java. I think it is a duplicate question – The Guest Dec 07 '15 at 22:11
  • http://stackoverflow.com/questions/13678221/how-to-get-multiple-substrings-from-string-in-android-java – PM 77-1 Dec 07 '15 at 22:12

0 Answers0