1  /  1  页   1 跳转 查看:1258

版主求教一个问题

版主求教一个问题

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" c />
<meta http-equiv="X-UA-Compatible" c />
<title>nothing is impossible</title>
<style type="text/css" media="screen">
* {margin:0;padding:0;}
body {font-family:Arial,Helvetica,sans-serif;font-size:12px;}
ul {list-style-type:none;}
</style>
</head>
<body>
<form><input type="checkbox" /><span>Juese Chirst,.,.,.,.,.,....</span></form>
</body>
<script type="text/javascript">
var htmlElem=document.getElementsByTagName('body')[0].getElementsByTagName('*');
var patternComma=/\u002c/g;var patternFullStop=/\u002e|\uff0e/g;
for (i=0;i<htmlElem.length;i++) {
if (!htmlElem.lastChild) continue;
if (htmlElem.nodeName=='SCRIPT') continue;
if (htmlElem.lastChild.nodeType==3) {
htmlElem.lastChild.nodeValue=htmlElem.lastChild.nodeValue.replace(patternComma,'\uff0c');
htmlElem.lastChild.nodeValue=htmlElem.lastChild.nodeValue.replace(patternFullStop,'\u3002');
}
}
</script>
</html>

如果让它支持更多符号。

=/\u002e|\uff0e/g

这个是半角转全角的java!
最后编辑skylun 最后编辑于 2008-07-01 23:30:07
 

回复: 版主求教一个问题

没有搞明白你打算问什么
 

回复 2F abc 的帖子

这个是半角转全角的JS,我想它支持所有这种特殊负号。自动转换。目前已经支持,。 还有:等等
 

参考如下代码

参考如下代码

                转全角半角(C#,VB.NET)
       
       
        /**//// <summary>
        /// 转全角的函数(SBC case)
        /// </summary>
        /// <param name="input">任意字符串</param>
        /// <returns>全角字符串</returns>
        ///<remarks>
        ///全角空格为12288,半角空格为32
        ///其他字符半角(33-126)与全角(65281-65374)的对应关系是:均相差65248
        ///</remarks>       
        public string ToSBC(string input)
        {
            //半角转全角:
            char[] c=input.ToCharArray();
            for (int i = 0; i < c.Length; i++)
            {
                if (c[i]==32)
                {
                    c[i]=(char)12288;
                    continue;
                }
                if (c[i]<127)
                    c[i]=(char)(c[i]+65248);
            }
            return new string(c);               
        }


        /**//// <summary>
        /// 转半角的函数(DBC case)
        /// </summary>
        /// <param name="input">任意字符串</param>
        /// <returns>半角字符串</returns>
        ///<remarks>
        ///全角空格为12288,半角空格为32
        ///其他字符半角(33-126)与全角(65281-65374)的对应关系是:均相差65248
        ///</remarks>
        public string ToDBC(string input)
        {   
            char[] c=input.ToCharArray();
            for (int i = 0; i < c.Length; i++)
            {
                if (c[i]==12288)
                {
                    c[i]= (char)32;
                    continue;
                }
                if (c[i]>65280 && c[i]<65375)
                    c[i]=(char)(c[i]-65248);
            }   
            return new string(c);
        }




VB版本:


<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
[url]http://www.CodeHighlighter.com/[/url]

-->    Public Function ToSBC()Function ToSBC(ByVal input As String) As String '转全角
        Dim c As Char() = input.ToCharArray
        Dim i As Integer = 0
        While i < c.Length
            If c(i) = ChrW(32) Then
                c(i) = ChrW(12288)
            ElseIf AscW(c(i)) < 127 Then
                c(i) = ChrW((AscW(c(i)) + 65248))
            End If
            System.Math.Min(System.Threading.Interlocked.Increment(i), i - 1)
        End While
        Return New String(c)
    End Function


    Public Function ToDBC()Function ToDBC(ByVal input As String) As String '转半角

        Dim c As Char() = input.ToCharArray
        Dim i As Integer = 0
        While i < c.Length
            If AscW(c(i)) = 12288 Then
                c(i) = ChrW(32)
            ElseIf AscW(c(i)) > 65280 AndAlso AscW(c(i)) < 65375 Then
                c(i) = ChrW(AscW(c(i)) - 65248)
            End If
            System.Math.Min(System.Threading.Interlocked.Increment(i), i - 1)
        End While
        Return New String(c)
    End Function


金鳞岂是池中物,一遇风云便化龙
 

回复:版主求教一个问题

字符的转换还没有遇到过
一直关注 .NET 却做着与开发无关的工作 呵呵~功力不够啊~~~~
 

回复:版主求教一个问题

谢谢老猫!继续关注你的网站!GOOD!

问个很菜的问题,  转全角半角(C#,VB.NET)  ==  等价于JS!
 
1  /  1  页   1 跳转

版权所有 老猫的理想   Sitemap

Powered by Discuz!NT 2.1.202    Copyright © 2001-2008 Comsenz Inc.
Processed in 0.046875 second(s) , 4 queries. 冀ICP备05001409号
返顶部