Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stripping a string to get values from within brackets 2

Status
Not open for further replies.

ftpdoo

Programmer
Aug 9, 2001
202
GB
Hi,

I've got a String which I'm want to check for the first "(" open bracket, starting from the RIGHT hand side. Then return the content from that bracket to the end of the string.

ie: strSQL:
INSERT INTO tblMyTable (Bla, Bla) VALUES (21, Fred)

I just want from the second bracket to be stored:
(21, Fred)

There may not always be two sets of brackets so it must check from the Right hand side.

Any idea's?? Thankx,
Jonathan
 
Use InStrRev and InStr

Code:
  Dim iStart As Integer
  Dim iEnd As Integer
  Dim s As String
  
  s = "INSERT INTO tblMyTable (Bla, Bla) VALUES (21, Fred)"
  
  iStart = InStrRev(s, "(", -1, vbTextCompare)
  If iStart Then
    iEnd = InStr(iStart, s, ")", vbTextCompare)
    
    MsgBox Mid(s, iStart, (iEnd - iStart) + 1)
  Else
    MsgBox "No ( found"
  End If
_________________
Bixarrio
e = m * (c ^ 2)
 


This should do it:

ReturnStr = Mid$(strSQL, InStrRev(strSQL, "("), InStrRev(strSQL, ")") - InStrRev(strSQL, "(") + 1)


Sunaj
 
Thankx,



How could I change this to return everything on the left hand side of the bracket instead of the right.

ie: INSERT INTO tblMyTable (Bla, Bla) VALUES

--------------------------------------------------
ReturnStr = Mid$(strSQL, InStrRev(strSQL, "("), InStrRev(strSQL, ")") - InStrRev(strSQL, "(") + 1)
---------------------------------------------------


 

left$(strSQL,InStrRev(strSQL, "(")-1)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top