Archived

This topic is now archived and is closed to further replies.

firefly2442

Visual Basic Question

Recommended Posts

If I have a String variable in Visual Basic is there a way to search through it? For example if the variable is "text.txt" could I search through it to find if there is a .txt in it? -Thanks

Share this post


Link to post
Share on other sites
two thoughts, "Like"
a = "this.txt" like "*.txt"
results in a being true

or using mid$, looping through the string, something like

searching = "testing.txt"
searchstring = "*.txt"
For a = 1 To (Len(searching) - Len(searchstring))
If Mid$(searching, a, Len(searchstring)) = searching Then
''Do something, a is the position
End If
Next a

Share this post


Link to post
Share on other sites
Don''t forget about Instr(string, search string). It will return the position of the search string in the string if it finds it or return 0.

if instr(blah, ".txt") <> 0 then
msgbox ".txt found!"
end if

Share this post


Link to post
Share on other sites