I have had to do this type of thing before with sql strings and have just
separated the string using string.split(" "). Then you get an array of
strings with each entry as a single word. Then you find the array index of
the beginning of the part you need and the index of the beginning of the
next part or the end o the array, whichever comes first. If your sql string
contains line feed/cr pairs you also need to split these since there may not
be a space between the words -in this case you would do something like (code
not checked):
Dim mySqlStr as string = "Select * from Orders O where O.Ordernum = 1234"
Dim splitChars() as Char = {" ", vbcrlf}
dim sqlArray as Array(of String) = mySqlStr.split(splitChars,
StringSplitOptions.RemoveEmptyEntries)
This would yield:
Select
*
From
Orders O
Where
O.Ordernum = 1234
....
To get the Select part you would concatinate sqlArray[0] (position of
Select) through sqlArray[2 - 1] (position of From), and add a space between
each one. You can use String.Join for this part
You will want to trim the strings and eliminate blank entries in the Array,
but this can be done in the Split method. You will also want to do a case
insensitive search for Select, From etc. or else convert everything to
UpperCase and then search for SELECT.
if you are using LINQ you could get the index values from a LINQ query.
HTH
Rick