hoffmandirt
July 22nd, 2005, 10:02 AM
I am trying to replace every closing brace "}" with "} // End of ." This code works fine in a regular text document, but it skips lines in the code editor. It will end up replacing every other brace. I'm not sure why, but I'm guessing it has something to do with the way the code editor works. Also before I added in the Regex.IsMatch this code would automatically insert xml comments ("///") on each line after it read an xml comment. I have no idea why it would have done this because I did not ever pass it the "///" to replace any text.
TextSelection ts = (TextSelection)applicationObject.ActiveDocument.Selection;
ts.StartOfDocument(true);
EditPoint stpt = ts.ActivePoint.CreateEditPoint();
while(!stpt.AtEndOfDocument)
{
ts.SelectLine();
string text = ts.Text;
if(Regex.IsMatch(text, "}"))
{
if((text.IndexOf("//") > -1))
text = "}";
text = text.Trim();
text = Regex.Replace(text, "}", "} // End of \n");
ts.Text = text;
}
stpt = ts.ActivePoint.CreateEditPoint();
}
ts.SelectAll();
string commandArgs = string.Empty;
applicationObject.ExecuteCommand("Edit.FormatSelection", commandArgs);
TextSelection ts = (TextSelection)applicationObject.ActiveDocument.Selection;
ts.StartOfDocument(true);
EditPoint stpt = ts.ActivePoint.CreateEditPoint();
while(!stpt.AtEndOfDocument)
{
ts.SelectLine();
string text = ts.Text;
if(Regex.IsMatch(text, "}"))
{
if((text.IndexOf("//") > -1))
text = "}";
text = text.Trim();
text = Regex.Replace(text, "}", "} // End of \n");
ts.Text = text;
}
stpt = ts.ActivePoint.CreateEditPoint();
}
ts.SelectAll();
string commandArgs = string.Empty;
applicationObject.ExecuteCommand("Edit.FormatSelection", commandArgs);