is there any kind of search/find string function in VB?
I tried
if string1 contains("L") then
etc etc
but it didnt work....
lets say I want to find all ":"'s in a string, and remove them.... how would i do that?
Printable View
is there any kind of search/find string function in VB?
I tried
if string1 contains("L") then
etc etc
but it didnt work....
lets say I want to find all ":"'s in a string, and remove them.... how would i do that?
Use the Replace function.
The code below will replace all of the colons in the text
assigned to strTemp with an empty string.
Hope this helps. :)Code:Private Sub Command1_Click()
Dim strTemp As String
strTemp = " Line1: " & " Line2: " & " Line3: "
Debug.Print strTemp 'Check value of strTemp
strTemp = Replace(strTemp, ":", "")
Debug.Print strTemp 'See that all :s have been removed
End Sub
Are using VB6?
Good.
To search in a string use InStr or InStrRev:
If "gh" is in the string then it will return the positionCode:Dim iCharPos As Integer
iCharPos = InStr(1, "abcdefghijklmnop", "gh", vbTextCompare)
where it found it in the string, if it is not in the string
then it will return 0. InStrRev is basically the same thing,
but it starts from the end of the string instead, this function
is only available in VB6.
To remove all occurences of a certain string within a
string then use Replace:
This function is only available in VB6. If you're not usingCode:Dim sNewString As String
sNewString = Replace("Please:remove:all:of:the:colons:.", ":", vbNullString, 1, , vbTextCompare)
VB6 then you'll have to use a loop and combination of InStr
and Mid to do the replacing.
Later.
I guess jcouture100 beat me to it while I was writing
my response up. You see that face in my code? That's
weird, I didn't know it was picked up in a code block, cool!
[Edited by SonGouki on 05-07-2000 at 01:30 AM]Code:Dim :) :o :p :( ;) As New BugInVBWorld
thank you.... very much...
I do have VB6