几个自己写的简单的字符处理方法(更新中)

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
     }
}
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值