Let’s say I have the string:
@"(Mg(Ni+(N(O2)3";
I am wondering if it is possible to replace occurrences of the string “(” but with the exception of “+(“. Thus result;
@"+Mg+Ni+(N+O2)3";
How would I go about doing this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can do this sort of more complex string replacements with regular expressions.
You can write the expression using a negative lookbehind to find a
(that is not preceded by a+(though there are simpler alternatives in this case, see @sch’s comment).Example: