Asp.net common function favorites page 1/2

Source: Internet
Author: User

/// <Summary>
/// Obtain the IP address of the site user
/// </Summary>
/// <Returns> </returns>
Public static string getuserip ()
{
Return httpcontext. Current. Request. servervariables ["remote_addr"]. tostring ();
}

/// <Summary>
/// Remove the last ',' sign of the 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;
}
}

///


// remove the first '/' of the string
///
// string to be processed
// returns the processed string
Public static string lostfirst (string CHR)
{< br> string flg = "";
If (CHR! = String. Empty | CHR! = NULL)
{< br> If (CHR. substring (0, 1) = "/")
flg = CHR. replace (CHR. substring (0, 1), "");
else
flg = CHR;
}< br> return flg;
}

///


// Replace special characters in HTML
///
/// text to be replaced.
// the replaced text.
Public static string htmlencode (string thestring)
{< br> thestring = thestring. replace (">", ">");
thestring = thestring. replace ("<", "<");
thestring = thestring. replace ("", "");
thestring = thestring. replace ("", "");
thestring = thestring. replace ("\" "," ");
thestring = thestring. replace ("\ '", "'");
thestring = thestring. replace ("\ n", "
");
return thestring;
}

/// <Summary>
/// Restore special characters in HTML
/// </Summary>
/// <Param name = "thestring"> the text to be restored. </Param>
/// <Returns> restored 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"> generation length </param>
/// <Returns> </returns>
Public static string number (INT length)
{
Return number (length, false );
}

///


// generate a random number
///
/// generation length
// whether to block the current thread before generation to avoid duplication
///
Public static string number (INT length, bool sleep)
{< br> If (sleep)
system. threading. thread. sleep (3);
string result = "";
system. random random = new random ();
for (INT I = 0; I {< br> result + = random. next (10 ). tostring ();
}< br> return result;
}

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.