asp.net common function collection 1th/2 page _ Application Tips

Source: Internet
Author: User
<summary>
Get site User IP
</summary>
<returns></returns>
public static string Getuserip ()
{
return httpcontext.current.request.servervariables["REMOTE_ADDR"]. ToString ();
}

<summary>
Remove the last ', ' number of a string
</summary>
<param name= "CHR": String to be processed </param>
<returns> returns the processed string </returns>
public static string Lost (String chr)
{
if (CHR = null | | chr = = string. Empty)
{
Return "";
}
Else
{
CHR = Chr. Remove (Chr. LastIndexOf (","));
return CHR;
}
}

<summary>
Remove the first '/' number of the string
</summary>
<param name= "CHR" > String to be processed </param>
<returns> returns the processed string </returns>
public static string Lostfirst (String chr)
{
String FLG = "";
if (Chr!= string. Empty | | CHR!= null)
{
if (Chr. Substring (0, 1) = = "/")
FLG = Chr. Replace (Chr. Substring (0, 1), "");
Else
FLG = CHR;
}
return FLG;
}

<summary>
Replace special characters in HTML
</summary>
<param name= "TheString" > Text that needs to be replaced. </param>
<returns> Replace the finished text. </returns>
public static string HtmlEncode (String thestring)
{
TheString = Thestring.replace (">", ">");
TheString = Thestring.replace ("<", "<");
TheString = Thestring.replace ("", "");
TheString = Thestring.replace ("", "");
TheString = Thestring.replace ("\" "," "");
TheString = Thestring.replace ("\", "'");
TheString = Thestring.replace ("\ n", "<br/>");
return thestring;
}

<summary>
Restore special characters in HTML
</summary>
<param name= "TheString" > Text that needs to be restored. </param>
<returns> restore good text. </returns>
public static string Htmldiscode (String thestring)
{
TheString = Thestring.replace (">", ">");
TheString = Thestring.replace ("<", "<");
TheString = Thestring.replace ("", "");
TheString = Thestring.replace ("", "");
TheString = Thestring.replace ("" "," "\");
TheString = Thestring.replace ("'", "\");
TheString = Thestring.replace ("<br/>", "\ n");
return thestring;
}



<summary>
Generate random numbers
</summary>
<param name= "Length" > Build length </param>
<returns></returns>
public static string number (int Length)
{
Return number (Length, false);
}

<summary>
Generate random numbers
</summary>
<param name= "Length" > Build length </param>
<param name= "Sleep" > whether to block the current thread before it is built to avoid duplication </param>
<returns></returns>
public static string number (int. Length, BOOL Sleep)
{
if (sleep)
System.Threading.Thread.Sleep (3);
string result = "";
System.Random Random = new Random ();
for (int i = 0; i < Length; i++)
{
result = random. Next (10). ToString ();
}
return result;
}
current 1/2 page   1 2 Next read the full text

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.