Tuesday, July 28, 2009

How do I write this substring code in Visual Basic?

I am writing a Visual Basic program, and I'm wondering what to do.


I want to write an if/then statement, where IF a certain substring is contained anywhere in a string variable, THEN this certain event will execute. But I'm not sure how to do that. Help?

How do I write this substring code in Visual Basic?
instr(1,"Today is a nice day.","nice",vbTextCompare )





use instr


1 ==%26gt; position to start search


"Today is a nice day." ==%26gt; String you want to search in


"nice" ==%26gt; String you are searching


vbTextCompare ==%26gt; compare type, text means ignore case


you can coose from binary and database compare





Return value is 0==%26gt; means not found and actual position of search string if found.


So you will be using


IF instr()%26lt;%26gt;0 then ==%26gt; if the string is found


No comments:

Post a Comment