c# - Comment and Uncomment Code -
im working on contextmenu shows on rightclick using mousedown event , 2of list contextmenu comment , uncomment code:
private void commentmenuitemclick(object sender, eventargs e) { rtb.selectedtext = "//" + rtb.selectedtext; lb.hide(); } private void uncommentmenuitemclick(object sender, eventargs e) { rtb.selectedtext = rtb.selectedtext.replace("//", ""); lb.hide(); rtb.selectioncolor = color.black; }
but comment when select , theres diff rows of text (selectall) output was:
but should like:
how can that? add // before diff rows of text? suggestion? uncomment code enough? or theres more better code that? pls lot!
--- edit
void parse() { string inputlanguage = "\n"; // foreach line in input, // identify key words , format them when adding rich text box. regex r = new regex("\\n"); string[] lines = r.split(inputlanguage); foreach (string l in lines) { parseline(l); } }
your problem adding '//' start of text.
you need parse selected text new line char , prepend '//' start of each line.
string builder described here, it's in system.text
something this:
private void commentmenuitemclick(object sender, eventargs e) { stringbuilder sw = new stringbuilder(); string line; stringreader rdr = new stringreader(rtb.selectedtext); line = rdr.readline(); while(line != null) { sw.appendline(string.isnullorwhitespace(line) ? "//" : "" + line); line= rdr.readline(); } rtb.selectedtext = sw.tostring(); lb.hide(); }
Comments
Post a Comment