.net - Get Word After String -


i want word following "from " part in db query. following code works, doesn't. seems depend on table name length.

private function gettablename(q string) string     'select * _table column '%test%'        dim frompos integer = q.tolower.indexof("from".tolower)      if frompos > -1         dim firstspacepos integer = q.tolower.indexof(chr(32), frompos)          if firstspacepos > -1             dim endspacepos integer = q.tolower.indexof(chr(32), firstspacepos + 1)              if endspacepos > -1                 'msgbox(q.substring(firstspacepos + 1, endspacepos - firstspacepos))                 return q.substring(firstspacepos + 1, endspacepos - firstspacepos)             else                 return ""             end if         else             return ""         end if     else         return ""     end if end function 

sometimes regex need (tested in linqpad, hence .dump() call).

dim queries = new list(of string)() { _     "select * my_table", _     "select * [dbo].[table spaces] tws tws.id = @id", _     "select * [dbo].[table spaces] tws tws.id in (select x.id [some_other_table] x)" _ }  each query string in queries     dim matches = regex.matches(query, "from\s+((?:(?:\[[^\]]+\])|[^\s])+)", regexoptions.ignorecase)     each m match in matches         m.groups(1).value.dump()     next next 

results:

my_table [dbo].[table spaces] [dbo].[table spaces] [some_other_table] 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -