Remove specified text from beginning of lines only if present (C#)

Posted by Zach on Stack Overflow See other posts from Stack Overflow or by Zach
Published on 2009-11-20T02:13:50Z Indexed on 2010/05/19 9:30 UTC
Read the original article Hit count: 146

I have a textbox in which the user can edit text, in a scripting language. I've figured out how to let the user comment out lines in one click, but can't seem to figure out how to uncomment properly. For example, if the box has:

Normal Text is here
More normal text
-- Commented text
-- More commented text
Normal Text again
--Commented Text Again

So, when the user selects any amount of text and decides to uncomment, the "--" is removed from the beginning of the lines that have it. The lines without the "--" should be unaffected. In short, I want an uncomment function that performs similar to the one in Visual Studio. Is there any way to accomplish this?

Thanks

© Stack Overflow or respective owner

Related posts about c#

Related posts about string-manipulation