Connecting Tech Pros Worldwide Forums | Help | Site Map

How to remove "(text)" from a string

Soundneedle
Guest
 
Posts: n/a
#1: Nov 13 '05
I have a string value that is equal to:
My neighbor has a dog (Fido).

How can I strip off the "(Fido)" part using VBA?


pietlinden@hotmail.com
Guest
 
Posts: n/a
#2: Nov 13 '05

re: How to remove "(text)" from a string


why would you want to do that with VBA? In VBA, you would have to do
this a record at a time, while using SQL you could do the *entire*
table at once.

use InStr() to get the position of the first open parenthesis, then
subtract one, then take everything to the left of it (Left$) and
finally Trim$ it.

Soundneedle
Guest
 
Posts: n/a
#3: Nov 13 '05

re: How to remove "(text)" from a string


I should elaborate....

Each string value will end in "(sometexthere)". Example
My first string (One)
My second string (Two)
My last string (Last)

What's the simplest code that will return everything to the left of the
first "("? I think it uses Left and Len. I just haven't figure it out
yet....

Soundneedle
Guest
 
Posts: n/a
#4: Nov 13 '05

re: How to remove "(text)" from a string


Just figured it out:
left([subject],instr([Subject],"(")-1)

Trevor Best
Guest
 
Posts: n/a
#5: Nov 13 '05

re: How to remove "(text)" from a string


Soundneedle wrote:[color=blue]
> I have a string value that is equal to:
> My neighbor has a dog (Fido).
>
> How can I strip off the "(Fido)" part using VBA?
>[/color]

Replace(text,"(fido)","")

--
[Oo=w=oO]

Closed Thread