you could use Instr to return the position of the string within the string:
Private Sub Command1_Click()
Dim sInf As String
Dim sNew As String
Dim fPos As Integer
Dim ePos As Integer
sInf = "sdkfjjk545lemon52kdfg"
fPos = InStr(1, sInf, "5")
ePos = InStr(fPos + 1, sInf, "5")
sNew = Mid(sInf, fPos + 1, ePos - fPos - 1)
MsgBox sNew
End Sub
Main Topics
Browse All Topics





by: wes_wilsonPosted on 2002-12-04 at 08:55:06ID: 7531968
I would suggest using the split function. The first and last elements of the array are garbage that you ignore, the center elements of the array have all the data you are searching for. If you want to put them back together, you can just use the join function. With the data you gave above this gives you an array with four elements as follows:
sdkfjjk
4
lemon
2kdfg
<VBCode>
Dim arrAnswers() As String
strTest = "sdkfjjk545lemon52kdfg"
arrAnswers = Split(strTest, "5")
</VBCode>