2

I'm working on a project to perform a query into a set of files where the query criteria are inputted by a user.

Essentially, if the user inputs:

/T"some text"

The query will look for any file that contains "some text."

If a user inputs:

/T"some text" /T"some other text"

The query will look for a file that contains both or at least one such criteria.

I have a couple of ideas about how to perform the query itself, but my question is how can I extract the text after the /T and in-between the quotes. I plan on putting the extracted string into some data structure.

I saw some examples of using IndexOf and such, but they would essentially look for the first instance of /T and extract everything else after that. Is there a method that would allow a bounded way of getting this information, whether it is some class or implementation of regex?

sujith karivelil
  • 28,671
  • 6
  • 55
  • 88
  • Appreciate your findings and ideas, proceed with them and come back if you are facing any specific issues/errors in implementation. Try to do it yourself don't expect capsule snippets – sujith karivelil Jul 31 '19 at 04:20
  • Would String.Split on /T work for you to get an array of strings? – Hursey Jul 31 '19 at 04:25
  • can the text itself contain quotation marks? If so, how would you escape them? You might consider using regex if you haven't already. – Jonathan Jul 31 '19 at 04:37

1 Answers1

1
var input = "/T\"some text\" /T\"some other text\"";
var criterias = input.Split(new[] { "/T\"", "\"" }, StringSplitOptions.None)
                     .Where(x => !string.IsNullOrWhiteSpace(x))
                     .ToList();
Slava Utesinov
  • 13,410
  • 2
  • 19
  • 26