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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trim characters after the first parenthesis

Status
Not open for further replies.

cic

Technical User
Apr 12, 2001
28
US
I am trying to trim a string up to a parenthesis. I am senting a city parameter to mapquest.However, some of our cities pull up with parenthesis. For example, Marble Falls (Austin). I don't want to pass anything after the first parenthesis. I am assuming I need to use a trim function but I am not sure how to go about doing it.

Thanks
 
The trim function only removes leading and trailing spaces. You will need to find the position of the first parenthases and use the left() function correspondingly, such as

strCity = "Marble Falls (Austin)"

strCity = Trim(Left(strCity, Instr(strCity, "(") - 1))

-----
Instr(strCity, "(") will return the position of the first instance of "(" in strCiry. Use this to determine the length you need to specify in the left() function (return the n leftmost characters) then trim() to remove any leading or trailing spaces
 
Dim strW
Dim nInstr
nInstr = Instr(strIn,"(")
if nInstr > 0 then
' not pass anything AFTER the first parenthesis???
strW = Left(strIN,nInstr) ' "Marble Falls ("
' OR include UP TO but NOT INCLUDING (
strW = RTrim(Left(strIn,nInstr - 1)) "Marble Falls"
else
strW = strin
end if Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
sorry, swampBoogie's method is better: if "(" is not in the string you're searching, it will pass left() a -1 and give you a runtime error
 
Thank you all for your help. I have inserted my code however I am getting the following error. I am a newbie at ASP so it is probably a simple fix. Can you help.

Error Type:
Microsoft VBScript runtime (0x800A0005)
Invalid procedure call or argument: 'Left'
/website/registration/form.asp, line 62
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top