|
-
May 6th, 2000, 11:27 AM
#1
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?
-
May 6th, 2000, 12:08 PM
#2
Addicted Member
Use the Replace function.
The code below will replace all of the colons in the text
assigned to strTemp with an empty string.
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
Hope this helps. 
-
May 6th, 2000, 12:08 PM
#3
Addicted Member
Are using VB6?
Good.
To search in a string use InStr or InStrRev:
Code:
Dim iCharPos As Integer
iCharPos = InStr(1, "abcdefghijklmnop", "gh", vbTextCompare)
If "gh" is in the string then it will return the position
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:
Code:
Dim sNewString As String
sNewString = Replace("Please:remove:all:of:the:colons:.", ":", vbNullString, 1, , vbTextCompare)
This function is only available in VB6. If you're not using
VB6 then you'll have to use a loop and combination of InStr
and Mid to do the replacing.
Later.
Dan PM
Analyst Programmer
VB6 SP3 (also VB4 16-bit sometimes  )
-
May 6th, 2000, 12:19 PM
#4
Addicted Member
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!
Code:
Dim :) :o :p :( ;) As New BugInVBWorld
[Edited by SonGouki on 05-07-2000 at 01:30 AM]
Dan PM
Analyst Programmer
VB6 SP3 (also VB4 16-bit sometimes  )
-
May 9th, 2000, 04:51 AM
#5
thank you.... very much...
I do have VB6
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|