vb.net - How do I find specific substring in a string -


my full question title long, should asked here:

how find instances of specific substring in string accounting spaces , special characters potentially being on either side of substring

what mean this. writing sql code formatting assistance program in vb.net. program when following on porrly writen sql. instance (and please ignore syntax failure here, not @ writting bad code in sql):

if exists(     select *     dbo.table     field1 = (if exists (select field1                                dbo.table1                                field2 = '123')                     select field1 table2) 

my program still in stages. have identified of keywords, , written code put them in proper case format. in bad code example above of selects select. have created list of key words in array form, , use array in following function:

private function findandreplace(byval findwhat string, _         byval replacewith string, byval focusline string) string     focusline = microsoft.visualbasic.strings.replace(focusline, findwhat, _         replacewith, 1, -1, constants.vbtextcompare)     return focusline end function 

the news works words select. words if, go, on, , end bit more challenging. if have word send, replace word send because end keyword. on many of these instances can account putting smaller words before larger words. have added send keyword because of number of times word appears in user messages on our systems.

i cannot seem account words on, if, or go. considered searching " go ", " on ", ")go ", " on(", etc. there times when go going first word on line...or only.

what need vb.net means of searching string of instances of given substring (such if). thinking check if first word in string, or seeing if surrounded combination of spaces or special characters (or not surrounded other letters , underscores, etc.). update met requirements, , leave others alone.

i drawing blank on how this, , use assistance.

i writing sql code formatting assistance program

i'd recommend starting existing sql parser.

pete sestoft's excellent programming language concepts book introduces parsing fundamentals including writing lexer , parser specifications micro-sql in chapter 3.

the open source irony project includes sql grammar sample.

use favourite search engine find others.

what need vb.net means of searching string of instances of given substring

there number of ways of achieving this:

  1. split string words , search words instances.
  2. use state machine iterate on string , check words after white space.

with option 2 can handle quoted strings , maintain index each word, here's short example in f#: http://fssnip.net/f6


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -