以下是代码片段:
StringWriter textBuffer = new StringWriter();
Match match= Regex.Match(HTMLStr,@"/",RegexOptions.IgnoreCase | piled);
if(match==null)
{
Response.Write(HTMLStr);
return;
}
string codeType = match.Groups["codeType"].Value;
string content = match.Groups["codeContent"].Value;
if(codeType==String.Empty || content==String.Empty)
{
Response.Write(HTMLStr);
return;
}
// MessageBox.Show(codeType);
// MessageBox.Show(content);
string[] sr = content.Split(Convert.ToChar("/n"));
if(codeType=="C#")
{
textBuffer.Write("<Csharp>/r/n");
foreach(string sourceLine in sr)
{
textBuffer.Write(FixCSLine(sourceLine)) ;
textBuffer.Write("/r/n");
}
textBuffer.Write("</Csharp>");
}
else if(codeType=="")
{
textBuffer.Write("<>/r/n");
foreach(string sourceLine in sr)
{
textBuffer.Write(FixJSLine(sourceLine)) ;
textBuffer.Write("/r/n");
}
textBuffer.Write("</>");
}
else if(codeType=="VB")
{
textBuffer.Write("<VB>/r/n");
foreach(string sourceLine in sr)
{
textBuffer.Write(FixVBLine(sourceLine)) ;
textBuffer.Write("/r/n");
}
textBuffer.Write("</VB>");
}
如果觉得《asp.net实现C#代码加亮显示》对你有帮助,请点赞、收藏,并留下你的观点哦!