×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Are you an
Engineering professional?
Join Eng-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Replacing Parantheses with Brackets

## Replacing Parantheses with Brackets

(OP)
Hello everyone!

Assuming that we have mathematical expression with several parentheses, how can a macro be written to pick up the string and replace second level parentheses with square brakets and the higher levels with curly brackets.
I have exhausted what little programing knowledge I have to come up with something, unfortunately the result has only been frustration.

If any one of you knows how to approach this please let me know. Or if anyone has any such code and cares to share, it will be greatly appreciated.

Much thanks.

FM

### RE: Replacing Parantheses with Brackets

uummm,

one such approach . . .
write vba code to:
1) obtain the text string
2) count the number of left (open) parantheses.
3) based on count, replace with squiggly (curly), square, or otherwise brackets.
4) do the same for the right parantheses.

or
1) obtain the text string
2) count total parantheses
3) based on count, replace text with choice of bracket. i.e. 6 total parantheses. parantheses 1 & 6 get curly, 2 & 5 get square, and 3 & 4 get normal parantheses. repeat if more parantheses are counted.

just thinking to myself. does this trigger any help in writing the code? please advise and perhaps i, or someone else, will generate the simple code.

good luck!
-pmover

### RE: Replacing Parantheses with Brackets

The Replace function takes 6 arguments:
Replace(expression, find, replace[, start[, count[, compare]]])

Start off by replacing all "(" with "{"

#### CODE

newstr=Replace(mystr,"(","{")
'then replace the first 2 "{" with "["
newstr = Replace(newstr,"{","[",,2)
'then replace the first  "[" with "("
newstr = Replace(newstr,"[","(",,1)
'repeat for other side

Good Luck
johnwm
________________________________________________________

Steam Engine enthusiasts: www.essexsteam.co.uk

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Close Box

# Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!