C # special character processing

Source: Internet
Author: User
Tags numeric

http://shashoutian2005.blog.163.com/blog/static/168541520093211750982/

http://apps.hi.baidu.com/share/detail/7168280

This is very practical: <script language= "JavaScript" > var reg= New RegExp ("End Ancient", "G"); Create a regular RegExp object var stringobj= "End ancient People's Republic, end ancient people"; var newstr=stringobj.replace (Reg, "China"); alert (NEWSTR); </script>

private static Regex regnumber = new Regex ("^[0-9]+$");
  private static Regex regnumbersign = new Regex ("^[+-]?[ 0-9]+$ ");
  private static Regex regdecimal = new Regex ("^[0-9]+[.")? [0-9]+$ ");
  private static Regex regdecimalsign = new Regex ("^[+-]?[ 0-9]+[.]? [0-9]+$ "); Equivalent to ^[+-]?/d+[.]? /d+$
  private static regex regemail = new Regex ("^[//w-]+@[//w-]+//." Com|net|org|edu|mil|tv|biz|info) $ ");//w a string of English letters or numbers, as in [a-za-z0-9] syntax
  private static Regex REGCHZN = New Regex ("[/u4e00-/u9fa5]");

The


   #region// encodes and converts incoming characters. or with Server.HTMLEncode (ENSTR)
  public static string Encodestr (String str)
  {
   str=str. Replace ("'", "" ");
   str=str. Replace ("/", "&quot;");
   str=str. Replace ("<", "&lt;");
   str=str. Replace (">", "&gt;");
   str=str. Replace ("n", "<br>");
   return str;
  }
        #endregion

#region//The conversion of the library characters into the display. or with Server.htmldecode (str)
public static string Decodestr (String str)
{
Str=str. Replace ("'", "" ");
Str=str. Replace ("&quot;", "/");
Str=str. Replace ("&lt;", "<");
Str=str. Replace ("&gt;", ">");
Str=str. Replace ("<br>", "/n");
return str;
}
#endregion

Numeric string Check
<summary>
Whether a numeric string
</summary>
<param name= "Inputdata" > Input string </param>
<returns></returns>
public static bool Isnumber (string inputdata)
{
Match m = Regnumber.match (Inputdata);
return m.success;
}
<summary>
Whether a numeric string can be signed or unsigned
</summary>
<param name= "Inputdata" > Input string </param>
<returns></returns>
public static bool Isnumbersign (string inputdata)
{
Match m = Regnumbersign.match (Inputdata);
return m.success;
}
<summary>
Whether it is a floating-point number
</summary>
<param name= "Inputdata" > Input string </param>
<returns></returns>
public static bool Isdecimal (string inputdata)
{
Match m = Regdecimal.match (Inputdata);
return m.success;
}
<summary>
is a floating-point number that can be signed or unsigned
</summary>
<param name= "Inputdata" > Input string </param>
<returns></returns>
public static bool Isdecimalsign (string inputdata)
{
Match m = Regdecimalsign.match (Inputdata);
return m.success;
}


<summary>
///Illegal character conversions
</summary>
<param name= "str" ></param>
<returns></returns>
public static string Replacestr (String str)
{
Str=str. Replace (",", "");
Str=str. Replace ("'", "");
Str=str. Replace (";", "");
Str=str. Replace (":", "");
Str=str. Replace ("/", "");
Str=str. Replace ("?", "");
Str=str. Replace ("<", "");
Str=str. Replace (">", "");
Str=str. Replace (".", "");
Str=str. Replace ("#", "");
Str=str. Replace ("%", "");
Str=str. Replace ("%", "");
Str=str. Replace ("^", "");
Str=str. Replace ("//", "");
Str=str. Replace ("@", "");
Str=str. Replace ("(", "");
Str=str. Replace (")", "" ");
Str=str. Replace ("*", "");
Str=str. Replace ("~", "");
Str=str. Replace ("'", "");
Str=str. Replace ("$", "");

return str;
}


//Check URL
public static bool Checkurl (String str)
{
Regex r=new Regex ("^http://" ([//w-]+//.) +[//w-]+ (/[//w-./?%&=]*)? $ ");

Match m = r.match (str);
if (m.success)
{
return true;
}
Else
{
return false;
}

}

//Date
public static bool Checkdate (String str)
{

Regex r = new Regex ("^ (//d{4})//-(//d{2})//-(//d{2}) $");
Match m =r.match (str);

if (m.success)
{
return true;
}
Else
{
return false;

}

}

public static bool Checkindate (String str)
{
Regex r = new Regex ("^ (
//d{4})//-(//d{2})//-(//d{2}) $");
Match m =r.match (str);
if (m.success)//format is correct
{
String m=m.tostring ();
char [] da = new Char[10];//char. Parse (M.tostring ());

M.copyto (0,da,0,10);

BOOL Bl=false;
String Yy= "";
String Mm= "";
String Dd= "";

#region Remove YYYY, MM, DD, respectively
for (int i=0;i<4;i++)
{
YY +=da[i]. ToString ();
}

for (int i=0;i<2;i++)
{
Mm+=da[5+i]. ToString ();
}

for (int i=0;i<2;i++)
{
Dd+=da[8+i]. ToString ();
}
#endregion

int Yearlow=int. Parse (configurationsettings.appsettings["Yearlow"]);
int Yearhigh=int. Parse (configurationsettings.appsettings["Yearhigh"]);
if (int. Parse (yy) <yearhigh && Int. Parse (yy) >yearlow)//
{
Whether the #region is a valid date value
BOOL B=true;
if (b)
{
BOOL B=false;
Switch (mm)
{
Case "a": b=true;
Break
Case "": b=true;
Break
Case "": b=true;
Break
Case "a": b=true;
Break
Case "a": b=true;
Break
Case "a": b=true;
Break
Case "Modified": b=true;
Break
Case "": b=true;
Break
Case "a": b=true;
Break
Case "ten": b=true;
Break
Case "one": b=true;
Break
Case "a": b=true;
Break
}
if (B)
{
Switch (DD)
{
Case "a": bl=true;
Break
Case "": bl=true;
Break
Case "": bl=true;
Break
Case "a": bl=true;
Break
Case "a": bl=true;
Break
Case "a": bl=true;
Break
Case "Modified": bl=true;
Break
Case "": bl=true;
Break
Case "a": bl=true;
Break
Case "ten": bl=true;
Break
Case "one": bl=true;
Break
Case "a": bl=true;
Break
Case "a": bl=true;
Break
Case "a": bl=true;
Break
Case "": bl=true;
Break
Case "": bl=true;
Break
Case "": bl=true;
Break
Case "a": bl=true;
Break
Case "a": bl=true;
Break
Case "a": bl=true;
Break
Case "": bl=true;
Break
Case "": bl=true;
Break
Case "": bl=true;
Break
Case "a": bl=true;
Break
Case "a": bl=true;
Break
Case "num": bl=true;
Break
Case "a": bl=true;
Break
Case "a": bl=true;
Break
Case "a": bl=true;
Break
Case "a": bl=true;
Break
Case "to": bl=true;
Break
}
}
}
#endregion
}
Else
{
Bl=false;
}

if (BL)
{
return true;
}
Else
{
return false;
}
}
Else
{
return false;
}

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.