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(),"<");
str = str.Replace(((char)62).ToString(),">");
str = str.Replace(((char)13).ToString(),"<br>");
str = str.Replace(((char)32).ToString()," ");
str = str.Replace(((char)34).ToString(),""");
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("<",((char)60).ToString());
str = str.Replace(">",((char)62).ToString());
str = str.Replace(" ",((char)32).ToString());
str = str.Replace(""",((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
}
}