Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The computer term for what you're doing is <a href="http://en.wikipedia.org/wiki/Lexical_analysis" rel="nofollow noreferrer">lexical analysis</a>; read that for a good summary of this common task.</p> <p>Based on your example, I'm guessing that you want whitespace to separate your words, but stuff in quotation marks should be treated as a "word" without the quotes.</p> <p>The simplest way to do this is to define a word as a regular expression:</p> <pre><code>([^"^\s]+)\s*|"([^"]+)"\s* </code></pre> <p>This expression states that a "word" is either (1) non-quote, non-whitespace text surrounded by whitespace, or (2) non-quote text surrounded by quotes (followed by some whitespace). Note the use of capturing parentheses to highlight the desired text.</p> <p>Armed with that regex, your algorithm is simple: search your text for the next "word" as defined by the capturing parentheses, and return it. Repeat that until you run out of "words".</p> <p>Here's the simplest bit of working code I could come up with, in VB.NET. Note that we have to check <em>both</em> groups for data since there are two sets of capturing parentheses.</p> <pre><code>Dim token As String Dim r As Regex = New Regex("([^""^\s]+)\s*|""([^""]+)""\s*") Dim m As Match = r.Match("this is a ""test string""") While m.Success token = m.Groups(1).ToString If token.length = 0 And m.Groups.Count &gt; 1 Then token = m.Groups(2).ToString End If m = m.NextMatch End While </code></pre> <p>Note 1: <a href="https://stackoverflow.com/users/1228/will">Will's</a> answer, above, is the same idea as this one. Hopefully this answer explains the details behind the scene a little better :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload