zoukankan      html  css  js  c++  java
  • 几个自己写的简单的字符处理方法(更新中)

    using System;
     
    namespace Public
    {
     
         ///<summary>
         /// CharacterOperation 文字处理方法。
         ///</summary>
         public class CharacterOperation
         {
     
             #region构造函数
             ///<summary>
             ///构造函数(静态方法)
             ///</summary>
             public CharacterOperation()
             {
             }
             #endregion
     
             #region字符替换为HTML字符串
             ///<summary>
             ///字符替换方法(" , > , < , 回车 , 空格)
             /// </summary>
             ///<param name="str">待替换字符串</param>
             ///<returns>替换后的字符串</returns>
             public static string ReplaceCharHTML(string str)
             {
                  str = str.Replace(((char)60).ToString(),"&lt;");
                  str = str.Replace(((char)62).ToString(),"&gt;");
                  str = str.Replace(((char)13).ToString(),"<br>");
                  str = str.Replace(((char)32).ToString(),"&nbsp;");
                  str = str.Replace(((char)34).ToString(),"&quot;");
                 
                  return str;
             }
             #endregion
     
             #region HTML字符串替换成原字符串(逆向方法)
             ///<summary>
             ///字符替换方法-逆向 (" , > , < , 回车 , 空格)
             /// </summary>
             ///<param name="str">待替换字符串</param>
             ///<returns>替换后的字符串</returns>
             public static string ReplaceCharText(string str)
             {
                  str = str.Replace("<br>",((char)13).ToString());
                  str = str.Replace("&lt;",((char)60).ToString());
                  str = str.Replace("&gt;",((char)62).ToString());
                  str = str.Replace("&nbsp;",((char)32).ToString());
                  str = str.Replace("&quot;",((char)34).ToString());
                 
                  return str;
             }
             #endregion
     
             #region判断是否为数字字符串
             ///<summary>
             ///判断是否为数字字符串
             ///</summary>
             ///<param name="str">需验证的字符串</param>
             ///<returns>判断结果,符合条件为True,不符合条件为False</returns>
             public static bool IsNumeric(string str)
             {
                  //判断是否为空
                  if (str == null || str.Length==0)
                  {
                       return false;
                  }
                  //循环检查每个字符
                  foreach(char c in str)
                  {
                       if (!Char.IsNumber(c))
                       {
                           return false;
                       }
                  }
                  return true;
             }
             #endregion
     
             #region static function ReplaceCharToShift 将字符串中小写字母转换为大写
             public static string ReplaceCharToShift(string str)
             {
                  string C="";
                  if(str!=null&&str.Length>0)
                  {
                       foreach(char c in str)
                       {
                           if((short)c>=97 && (short)c<=122)
                           {
                                C+=(char)((short)c-32);
                           }
                           else
                           {
                                C+=c;
                           }
                       }
                  }
     
                  return C;
             }
             #endregion
     
             #region static function order Char 字符串内 字母排序
             public static string CharOrder(string str)
             {
                  string[] str2=new string[str.Length];
                  int i=0;
                  foreach(char c in str)
                  {
                       str2[i]=c.ToString();
                       i++;
                  }
                 
                  Array.Sort(str2);
     
                  str="";
                  for(i=0;i<str2.Length;i++)
                  {
                       str+=str2[i];
                  }
                 
                  return str;
             }
             #endregion
         }
    }
     
  • 相关阅读:
    几种类间关系:继承、实现、依赖、关联、聚合、组合及UML变现图(转)
    StarUML指导手册(转)
    hook(转)
    DancingLinks简介(转)
    (转)用宏获取函数名
    UML中关联和依赖的区别
    “智商平平”学软件(转)
    生产者消费者问题Semaphore
    [转] UML中关联、依赖、聚集等关系的异同
    最近要看的东西
  • 原文地址:https://www.cnblogs.com/ZetaChow/p/2237453.html
Copyright © 2011-2022 走看看