盾怪网教程:是一个免费提供流行杀毒软件教程、在线学习分享的学习平台!

对VB/ASP源代码进行着色

时间:2024/6/1作者:未知来源:盾怪网教程人气:

[摘要]这类程序在网上很多,但拿来练练“正则表达式”也不错的,所以就随手写了这个,现在只能对代码(函数,关键字,对象,字符串)进行着色,下一步想对函数块加入折叠效果(.NET代码编辑器的效果)。 演示效果代...

这类程序在网上很多,但拿来练练“正则表达式”也不错的,所以就随手写了这个,现在只能对代码(函数,关键字,对象,字符串)进行着色,下一步想对函数块加入折叠效果(.NET代码编辑器的效果)。

演示效果代码:(ChangeVBToColor函数即是重点函数)
---------------------------------------------------------------------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<style type="text/css">
<!--
body {
font-family: "宋体";
font-size: 12px;
color: #333333;
}
.Text {
font-family: "宋体";
font-size: 12px;
border: 1px solid #333333;
}
td {
font-family: "宋体";
font-size: 12px;
}
-->
</style>
</head>

<body>
<table width="760" height="399" border="0" cellpadding="0" cellspacing="2">
<tr>
<td height="302" valign="top"><form name="form1" method="post" action="">
<div align="center">
<textarea name="Content" cols="120" rows="25" class="Text" id="Content"></textarea>
<br>
<input name="btnShow" type="button" class="Text" id="btnShow" value="显 示" OnClick="GetHtmlContent()">
</div>
</form></td>
</tr>
<tr>
<td height="91"><span id="sHtml"></span></td>
</tr>
</table>
<SCRIPT LANGUAGE="VBScript">
Sub GetHtmlContent
'GGG form1.Content.value
document.all.sHtml.innerHTML=ChangeVbToColor(HtmlEncode(form1.Content.value))
End Sub

Function ChangeVbToColor(ByVal sText)
Dim re,Matches,i
Dim oneReg
Set re=new RegExp
re.IgnoreCase =true
re.Global=true
'转换函数块
're.Pattern="Function (\w+)(\([^\)]*\))?([^End Function]*)End Function"
'sText=re.Replace(sText,"<font color=red>$1</font>")
'sText=re.Replace(sText,"<img src=http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif>$3")
'alert sText
'转换保留字为[蓝色]
re.Pattern="(\bAnd\b

关键词:对VB/ASP源代码进行着色




Copyright © 2012-2018 盾怪网教程(http://www.dunguai.com) .All Rights Reserved 网站地图 友情链接

免责声明:本站资源均来自互联网收集 如有侵犯到您利益的地方请及时联系管理删除,敬请见谅!

QQ:1006262270   邮箱:kfyvi376850063@126.com   手机版