×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • 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.

Students Click Here

Replacing Parantheses with Brackets

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
________________________________________________________
To get the best from these forums read FAQ731-376 before posting

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.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login



News


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:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close