RT
public string[] GetString(string htmlStr)
{
Regex regObj = new Regex("^[?\uFF10-\uFF19\uFF41-\uFF5A\uFF21-\uFF3A]*$",RegexOptions.Compiled|RegexOptions.IgnoreCase);
string [] strAry = new string [regObj.Matches(htmlStr).Count] ;
int i = 0;
foreach (Match matchItem in regObj.Matches(htmlStr))
{
strAry[i] = matchItem.Value;
i++;
}
return strAry ;
}
这是我原有的代码
这一句
new Regex("^[?\uFF10-\uFF19\uFF41-\uFF5A\uFF21-\uFF3A]*$",RegexOptions.Compiled|RegexOptions.IgnoreCase);
怎么写才能匹配出全角字符

解决方案 »

  1.   

    非要用正则表达式吗?下面这段代码就是全角转半角的
    public static string CharConverter(string source)
    {
    System.Text.StringBuilder result = new System.Text.StringBuilder(source.Length, source.Length);
    for (int i=0; i<source.Length; i++)
    {
    if (source[i] >= 65281 && source[i] <= 65373)
    {
    result.Append((char)(source[i] - 65248));
    }
    else if (source[i] == 12288)
    {
    result.Append(' ');
    }
    else
    {
    result.Append(source[i]);
    }
    }
    return result.ToString();
    }
      

  2.   

    this.txt.Attributes.Add("onchange","WideCharToChar()");js实现半全角转换function WideCharToChar(){
        c =event.srcElement.value;
       myArray= new Array();
     for(i=0;i<c.length;i++)
      {
         
       if(c.charCodeAt!=null&&String.fromCharCode!=null)
      {
               var charCode=c.charCodeAt(i);
                  if(charCode>0xfee0){
                  
                      myArray[i]=String.fromCharCode(charCode-0xfee0);
                     
                    }
                  else
                          myArray[i]=String.fromCharCode(charCode);
                 
                 }
              }
            event.srcElement.value=str;
    }