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
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
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
Replace(expression, find, replace[, start[, count[, compare]]])
Start off by replacing all "(" with "{"
CODE
'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