remove brackets

H

hughess7

Hi all

Using a query, I want to display the text in a field without its surrounding
brackets, please can you tell me the best way to achieve this?

I know you can use replace and instr functions

eg Expr2: Right([Short_Dsc],InStr([Short_dsc],")")-1) or
Expr1: Replace([short_Dsc],"(","")

but which is the best to use and how would I combine this with not
displaying the last bracket too... ?

Thanks
 
B

BruceM

There are a number of ways to do this. One possibility if the parentheses
are always at the beginning and end of the field:
ShortField: Mid([Short_Dsc],2,Len([Short_Dsc])-2)

If the parentheses are not necessarily at the beginning and end you could
nest one Replace within another:
ShortField: Replace(Replace([Short_Dsc],"(",""),")","")
This should work no matter where the parentheses are.
 
B

Brendan Reynolds

hughess7 said:
Hi all

Using a query, I want to display the text in a field without its
surrounding
brackets, please can you tell me the best way to achieve this?

I know you can use replace and instr functions

eg Expr2: Right([Short_Dsc],InStr([Short_dsc],")")-1) or
Expr1: Replace([short_Dsc],"(","")

but which is the best to use and how would I combine this with not
displaying the last bracket too... ?

Thanks

Don't know about 'best' but something like the following ...

Replace(Replace("[short_Dsc]", "[", ""), "]", "")

.... should replace the two brackets.

That is to say, nest one call to the Replace function within the other.
 
H

hughess7

Thank you! In this case they are always at the beginning and the end but it
is good to see an example if they were in any part of the string too :)

BruceM said:
There are a number of ways to do this. One possibility if the parentheses
are always at the beginning and end of the field:
ShortField: Mid([Short_Dsc],2,Len([Short_Dsc])-2)

If the parentheses are not necessarily at the beginning and end you could
nest one Replace within another:
ShortField: Replace(Replace([Short_Dsc],"(",""),")","")
This should work no matter where the parentheses are.


hughess7 said:
Hi all

Using a query, I want to display the text in a field without its
surrounding
brackets, please can you tell me the best way to achieve this?

I know you can use replace and instr functions

eg Expr2: Right([Short_Dsc],InStr([Short_dsc],")")-1) or
Expr1: Replace([short_Dsc],"(","")

but which is the best to use and how would I combine this with not
displaying the last bracket too... ?

Thanks
 
H

hughess7

I never think to use the nested approach and sometimes struggle with the
exact syntax. Thanks Brendan :)

Brendan Reynolds said:
hughess7 said:
Hi all

Using a query, I want to display the text in a field without its
surrounding
brackets, please can you tell me the best way to achieve this?

I know you can use replace and instr functions

eg Expr2: Right([Short_Dsc],InStr([Short_dsc],")")-1) or
Expr1: Replace([short_Dsc],"(","")

but which is the best to use and how would I combine this with not
displaying the last bracket too... ?

Thanks

Don't know about 'best' but something like the following ...

Replace(Replace("[short_Dsc]", "[", ""), "]", "")

... should replace the two brackets.

That is to say, nest one call to the Replace function within the other.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top