Read a string
-
Hi. I’m trying to write and
if then
statement that checks to see if a string contains a certain value. Here is how I thought it worked:If TheString.IndexOfAny(“This Text”) then
I want the statement to return True if the string contains “This Text” anywhere within the string. Can anybody tell me how this should be written? Thanks Brad -
Hi. I’m trying to write and
if then
statement that checks to see if a string contains a certain value. Here is how I thought it worked:If TheString.IndexOfAny(“This Text”) then
I want the statement to return True if the string contains “This Text” anywhere within the string. Can anybody tell me how this should be written? Thanks BradThere is a function in Microsoft.VisualBasic called Instr that can, given two strings, give you the number of times that string2 occurs in string1. Try using this function
Function ContainsStr(Str1 As String, Str2 as String) As Boolean Return (Microsoft.VisualBasic.Instr(Str1, Str2) > 0) End Function
Hope This Helps -
There is a function in Microsoft.VisualBasic called Instr that can, given two strings, give you the number of times that string2 occurs in string1. Try using this function
Function ContainsStr(Str1 As String, Str2 as String) As Boolean Return (Microsoft.VisualBasic.Instr(Str1, Str2) > 0) End Function
Hope This HelpsThis looks like it will do the trick. Thank you very much! Brad
-
Hi. I’m trying to write and
if then
statement that checks to see if a string contains a certain value. Here is how I thought it worked:If TheString.IndexOfAny(“This Text”) then
I want the statement to return True if the string contains “This Text” anywhere within the string. Can anybody tell me how this should be written? Thanks Brad -
Hi ROLI. I didn't completely understand the use of IndexOfAny. This thread contains a good explanation for anybody who is interested: http://www.visualbasicforum.com/showthread.php?t=175579 Thanks for you help. Brad
-
Hi. I’m trying to write and
if then
statement that checks to see if a string contains a certain value. Here is how I thought it worked:If TheString.IndexOfAny(“This Text”) then
I want the statement to return True if the string contains “This Text” anywhere within the string. Can anybody tell me how this should be written? Thanks Braddeclare a boolean variable as say
Dim val As boolean
then after the statement,If TheString.IndexOfAny(“This Text”) then
typeval="true" Endif
ORreturn "true":|
u can then reference variable val elsewhere as the value returned