经过了上个星期的努力学习,对处理html又有了新的发现
感觉真的很不错
可以说js的威力在处理html代码方面我又有所领悟了
1、截取特定长度字符串

 Public Shared Function CutString1()Function CutString1(ByVal str As String, ByVal length As Integer) As String
    Public Shared Function CutString1()Function CutString1(ByVal str As String, ByVal length As Integer) As String

 Dim i As Integer = 0
        Dim i As Integer = 0 Dim j As Integer = 0
        Dim j As Integer = 0 For Each chr As Char In str
        For Each chr As Char In str If Asc(chr) > 127 Then
            If Asc(chr) > 127 Then i = i + 2
                i = i + 2 Else
            Else i += 1
                i += 1 If (i > length) Then
                If (i > length) Then str = str.Substring(0, j) + "
                    str = str.Substring(0, j) + " "
" Exit For
                    Exit For End If
                End If End If
            End If j += 1
            j += 1 Next
        Next Return str
        Return str
 End Function
    End Function
 Public Function HtmlEncode()Function HtmlEncode(ByVal str As String) As String
Public Function HtmlEncode()Function HtmlEncode(ByVal str As String) As String Dim L As Integer
        Dim L As Integer Dim result As String
        Dim result As String If str = "" Then
        If str = "" Then Return ""
            Return "" End If
        End If L = Len(str)
        L = Len(str) Dim i As Integer
        Dim i As Integer For i = 1 To L
        For i = 1 To L Select Case Mid(str, i, 1)
            Select Case Mid(str, i, 1) Case Chr(13)
                Case Chr(13) result = result + "<br>"
                    result = result + "<br>" Case Chr(34)
                Case Chr(34) result = result + """
                    result = result + """ Case Chr(32)
                Case Chr(32) 'result=result+" "
                    'result=result+" " If i + 1 <= L And i - 1 > 0 Then
                    If i + 1 <= L And i - 1 > 0 Then If Mid(str, i + 1, 1) = Chr(32) Or Mid(str, i + 1, 1) = Chr(9) Or Mid(str, i - 1, 1) = Chr(32) Or Mid(str, i - 1, 1) = Chr(9) Then
                        If Mid(str, i + 1, 1) = Chr(32) Or Mid(str, i + 1, 1) = Chr(9) Or Mid(str, i - 1, 1) = Chr(32) Or Mid(str, i - 1, 1) = Chr(9) Then result = result + " "
                            result = result + " " Else
                        Else result = result + " "
                            result = result + " " End If
                        End If Else
                    Else result = result + " "
                        result = result + " " End If
                    End If Case Chr(9)
                Case Chr(9) result = result + "    "
                    result = result + "    " Case Else
                Case Else result = result + Mid(str, i, 1)
                    result = result + Mid(str, i, 1) End Select
            End Select Next
        Next Return result
        Return result End Function
    End Function3、在textarea(textbox里面的textmode为dul),对其输入的字符转换成html格式输出

 Public Shared Function StripHTML()Function StripHTML(ByVal strHtml As String) As String
    Public Shared Function StripHTML()Function StripHTML(ByVal strHtml As String) As String Dim aryReg() As String = New String() {"<script[^>]*?>.*?</script>", "<(\/\s*)?!?((\w+:)?\w+)(\w+(\s*=?\s*(([""'])(\\[""'tbnr]|[^\7])*?\7|\w+)|.{0})|\s)*?(\/\s*)?>", "([\r\n])[\s]+", "&(quot|#34);", "&(amp|#38);", "&(lt|#60);", "&(gt|#62);", "&(nbsp|#160);", "&(iexcl|#161);", "&(cent|#162);", "&(pound|#163);", "&(copy|#169);", "&#(\d+);", "-->", "<!--.*\n"}
        Dim aryReg() As String = New String() {"<script[^>]*?>.*?</script>", "<(\/\s*)?!?((\w+:)?\w+)(\w+(\s*=?\s*(([""'])(\\[""'tbnr]|[^\7])*?\7|\w+)|.{0})|\s)*?(\/\s*)?>", "([\r\n])[\s]+", "&(quot|#34);", "&(amp|#38);", "&(lt|#60);", "&(gt|#62);", "&(nbsp|#160);", "&(iexcl|#161);", "&(cent|#162);", "&(pound|#163);", "&(copy|#169);", "&#(\d+);", "-->", "<!--.*\n"}
 Dim aryRep() As String = {"", "", "", """", "&", "", "", " ", "\xa1", Chr(161), "\xa2", Chr(162), "\xa3", Chr(163), "\xa9", Chr(169), "", "\r\n", ""}
        Dim aryRep() As String = {"", "", "", """", "&", "", "", " ", "\xa1", Chr(161), "\xa2", Chr(162), "\xa3", Chr(163), "\xa9", Chr(169), "", "\r\n", ""}




 Dim NewReg As String = aryReg(0)
        Dim NewReg As String = aryReg(0) Dim strOutput As String = strHtml
        Dim strOutput As String = strHtml Dim i As Integer
        Dim i As Integer For i = 0 To aryReg.Length - 1 Step i + 1
        For i = 0 To aryReg.Length - 1 Step i + 1 Dim regex As Regex = New Regex(aryReg(i), RegexOptions.IgnoreCase)
            Dim regex As Regex = New Regex(aryReg(i), RegexOptions.IgnoreCase) strOutput = regex.Replace(strOutput, aryRep(i))
            strOutput = regex.Replace(strOutput, aryRep(i)) Next
        Next
 strOutput.Replace("<", "")
        strOutput.Replace("<", "") strOutput.Replace(">", "")
        strOutput.Replace(">", "") strOutput.Replace("\r\n", "")
        strOutput.Replace("\r\n", "")

 Return strOutput
        Return strOutput End Function
    End Function var pltsPop=null;
var pltsPop=null; var pltsoffsetX = 10;
var pltsoffsetX = 10; var pltsoffsetY = 15;
var pltsoffsetY = 15; var pltsPopbg="#ffff00";
var pltsPopbg="#ffff00"; var pltsPopfg="#111111";
var pltsPopfg="#111111"; var pltsTitle="";
var pltsTitle=""; document.write('<div id=pltsTipLayer style="display: none;position: absolute; z-index:10001"></div>');
document.write('<div id=pltsTipLayer style="display: none;position: absolute; z-index:10001"></div>'); function pltsinits()
function pltsinits()

 {
{ document.onmouseover   = plts;
    document.onmouseover   = plts; document.onmousemove = moveToMouseLoc;
    document.onmousemove = moveToMouseLoc; }
} function plts()
function plts()

 {  var o=event.srcElement;
{  var o=event.srcElement;
 if(o.alt!=null && o.alt!="")
    if(o.alt!=null && o.alt!="") {o.dypop=o.alt;o.alt=""};
{o.dypop=o.alt;o.alt=""};
 if(o.title!=null && o.title!="")
    if(o.title!=null && o.title!="") {o.dypop=o.title;o.title=""};
{o.dypop=o.title;o.title=""}; pltsPop=o.dypop;
    pltsPop=o.dypop; if(pltsPop!=null&&pltsPop!=""&&typeof(pltsPop)!="undefined")
    if(pltsPop!=null&&pltsPop!=""&&typeof(pltsPop)!="undefined")
 
     {
{ pltsTipLayer.style.left=-1000;
pltsTipLayer.style.left=-1000; pltsTipLayer.style.display='';
pltsTipLayer.style.display=''; var Msg=pltsPop.replace(/\n/g,"<br>");
var Msg=pltsPop.replace(/\n/g,"<br>"); Msg=Msg.replace(/\0x13/g,"<br>");
Msg=Msg.replace(/\0x13/g,"<br>");
 var re=/\
var re=/\ {(.[^\
{(.[^\ {]*)\}/ig;
{]*)\}/ig; if(!re.test(Msg))pltsTitle="[MyTopWin.Com] 拓文CMS ASP.net系统";
if(!re.test(Msg))pltsTitle="[MyTopWin.Com] 拓文CMS ASP.net系统";
 else
else {
{
 re=/\
   re=/\ {(.[^\
{(.[^\ {]*)\}(.*)/ig;
{]*)\}(.*)/ig; pltsTitle=Msg.replace(re,"$1")+" ";
     pltsTitle=Msg.replace(re,"$1")+" ";
 re=/\
   re=/\ {(.[^\
{(.[^\ {]*)\}/ig;
{]*)\}/ig; Msg=Msg.replace(re,"");
   Msg=Msg.replace(re,""); Msg=Msg.replace("<br>","");}
   Msg=Msg.replace("<br>","");} 
   var content =
        var content = '<table style="FILTER:alpha(opacity=90) shadow(color=#bbbbbb,direction=150);" id=toolTipTalbe border=0><tr><td width="100%"><table class=selet_bg cellspacing="0" cellpadding="0" style="width:100%" style="font size:11px;">'+
       '<table style="FILTER:alpha(opacity=90) shadow(color=#bbbbbb,direction=150);" id=toolTipTalbe border=0><tr><td width="100%"><table class=selet_bg cellspacing="0" cellpadding="0" style="width:100%" style="font size:11px;">'+ '<tr id=pltsPoptop><th height=12 valign=bottom class=header><p id=topleft align=left>↖'+pltsTitle+'</p><p id=topright align=right style="display:none">'+pltsTitle+'↗</font></th></tr>'+
       '<tr id=pltsPoptop><th height=12 valign=bottom class=header><p id=topleft align=left>↖'+pltsTitle+'</p><p id=topright align=right style="display:none">'+pltsTitle+'↗</font></th></tr>'+ '<tr><td style="padding-left:10px;padding-right:10px;padding-top: 4px;padding-bottom:4px;line-height:135%">'+Msg+'</td></tr>'+
       '<tr><td style="padding-left:10px;padding-right:10px;padding-top: 4px;padding-bottom:4px;line-height:135%">'+Msg+'</td></tr>'+ '<tr id=pltsPopbot style="display:none"><th height=12 valign=bottom class=header><p id=botleft align=left>↙'+pltsTitle+'</p><p id=botright align=right style="display:none">'+pltsTitle+'↘</font></th></tr>'+
       '<tr id=pltsPopbot style="display:none"><th height=12 valign=bottom class=header><p id=botleft align=left>↙'+pltsTitle+'</p><p id=botright align=right style="display:none">'+pltsTitle+'↘</font></th></tr>'+ '</table></td></tr></table>';
       '</table></td></tr></table>'; pltsTipLayer.innerHTML=content;
        pltsTipLayer.innerHTML=content; toolTipTalbe.style.width=Math.min(pltsTipLayer.clientWidth,document.body.clientWidth/2.2);
        toolTipTalbe.style.width=Math.min(pltsTipLayer.clientWidth,document.body.clientWidth/2.2); moveToMouseLoc();
        moveToMouseLoc(); return true;
        return true; }
       } else
    else
 
     {
{ pltsTipLayer.innerHTML='';
     pltsTipLayer.innerHTML=''; pltsTipLayer.style.display='none';
       pltsTipLayer.style.display='none'; return true;
        return true; }
    } }
}
 function moveToMouseLoc()
function moveToMouseLoc()

 {
{ if(pltsTipLayer.innerHTML=='')return true;
if(pltsTipLayer.innerHTML=='')return true; var MouseX=event.x;
var MouseX=event.x; var MouseY=event.y;
var MouseY=event.y; //window.status=event.y;
//window.status=event.y; var popHeight=pltsTipLayer.clientHeight;
var popHeight=pltsTipLayer.clientHeight; var popWidth=pltsTipLayer.clientWidth;
var popWidth=pltsTipLayer.clientWidth; if(MouseY+pltsoffsetY+popHeight>document.body.clientHeight)
if(MouseY+pltsoffsetY+popHeight>document.body.clientHeight)

 {
{ popTopAdjust=-popHeight-pltsoffsetY*1.5;
    popTopAdjust=-popHeight-pltsoffsetY*1.5; pltsPoptop.style.display="none";
    pltsPoptop.style.display="none"; pltsPopbot.style.display="";
    pltsPopbot.style.display=""; }
} else
  else

 {
{ popTopAdjust=0;
     popTopAdjust=0; pltsPoptop.style.display="";
    pltsPoptop.style.display=""; pltsPopbot.style.display="none";
    pltsPopbot.style.display="none"; }
} if(MouseX+pltsoffsetX+popWidth>document.body.clientWidth)
if(MouseX+pltsoffsetX+popWidth>document.body.clientWidth)

 {
{ popLeftAdjust=-popWidth-pltsoffsetX*2;
  popLeftAdjust=-popWidth-pltsoffsetX*2; topleft.style.display="none";
  topleft.style.display="none"; botleft.style.display="none";
  botleft.style.display="none"; topright.style.display="";
  topright.style.display=""; botright.style.display="";
  botright.style.display=""; }
} else
else

 {
{ popLeftAdjust=0;
  popLeftAdjust=0; topleft.style.display="";
  topleft.style.display=""; botleft.style.display="";
  botleft.style.display=""; topright.style.display="none";
  topright.style.display="none"; botright.style.display="none";
  botright.style.display="none"; }
} pltsTipLayer.style.left=MouseX+pltsoffsetX+document.body.scrollLeft+popLeftAdjust;
pltsTipLayer.style.left=MouseX+pltsoffsetX+document.body.scrollLeft+popLeftAdjust; pltsTipLayer.style.top=MouseY+pltsoffsetY+document.body.scrollTop+popTopAdjust;
pltsTipLayer.style.top=MouseY+pltsoffsetY+document.body.scrollTop+popTopAdjust; return true;
   return true; }
} pltsinits();
pltsinits();
评论