There are various ways of doing this:
Code:
Dim NewString As String, TheString As String
Dim Number As Integer
TheString = "Text Here (93)"
'Takes that first 9 chars and puts them into a string
NewString = Left$(TheString, 9)
Number = RemoveBrackets(Right$(TheString, 4))
Code:
Dim NewString As String, TheString As String
Dim Number As Integer
TheString = "Text Here (93)"
'Finds the first bracket and takes everything before that
'and then removes the space
NewString = Trim$(Left$(TheString, CLng(InStr(1, TheString, "(", vbTextCompare) - 1)))
'Finds the brackets (doesn't assume that they are at the end)
Number = RemoveBrackets(Right$(TheString, CLng(InStr(1, TheString, ")", vbTextCompare) - Len(NewString))))
Code:
'//REQUIRES VB6
Dim NewStringArr() As String, TheString As String
Dim NewString As String
Dim Number As Integer
Dim i As Integer
TheString = "Text Here (93)"
NewStringArr = Split(TheString, " ")
For i = 0 To UBound(NewStringArr)
If NewStringArr(i) Like "(*)" Then
Number = RemoveBrackets(NewStringArr(i))
Exit For
Else:
NewString = NewString & NewStringArr(i) & " "
End If
Next i
NewString = Trim$(NewString)
Or
Code:
'// REQUIRES VB 6
Dim NewString As String, TheString As String
Dim Number As Integer
TheString = "Text Here (93)"
'Finds the first bracket and takes everything before that
'and then removes the space
NewString = Trim$(Left$(TheString, CLng(InStrRev(TheString, "(", , vbTextCompare) - 1)))
Number = RemoveBrackets(Right$(TheString, CLng(InStrRev(TheString, ")", , vbTextCompare) - 1) - Len(NewString)))
The function they all use:
Code:
Function RemoveBrackets(BracketString As String) As Integer
'Remove Any Spaces
BracketString = Trim$(BracketString)
'//If you have VB6 Then:
BracketString = Replace(BracketString, "(", "")
BracketString = Replace(BracketString, ")", "")
BracketString = Trim$(BracketString)
RemoveBrackets = CInt(BracketString)
'//Otherwise:
BracketString = Left$(BracketString, 3)
BracketString = Trim$(BracketString)
BracketString = Right$(BracketString, 2)
BracketString = Trim$(BracketString)
RemoveBrackets = CInt(BracketString)
End Function
I hope you find one of these useful,
Me.
[Edited by V(ery) Basic on 08-27-2000 at 06:12 AM]