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

Replacing Parantheses with Brackets

Status
Not open for further replies.

FM1

Structural
Joined
Dec 16, 2001
Messages
67
Location
US
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
 
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
 
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:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top