asp.net完成C#代碼加亮顯示
發(fā)表時(shí)間:2024-01-23 來(lái)源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]以下是代碼片段:StringWriter textBuffer = new StringWriter();Match match= Regex.Match(HTMLStr,@"\",RegexOptions.IgnoreCase RegexOptions.Compiled)...
以下是代碼片段:
StringWriter textBuffer = new StringWriter();
Match match= Regex.Match(HTMLStr,@"\",RegexOptions.IgnoreCase RegexOptions.Compiled);
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=="JScript.Net")
{
textBuffer.Write("<JScript.Net>\r\n");
foreach(string sourceLine in sr)
{
textBuffer.Write(FixJSLine(sourceLine)) ;
textBuffer.Write("\r\n");
}
textBuffer.Write("</JScript.Net>");
}
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>");
}