当前位置: 移动技术网 > IT编程>开发语言>Asp > asp.net常用函数收藏第1/2页

asp.net常用函数收藏第1/2页

2018年05月29日  | 移动技术网IT编程  | 我要评论
/// <summary>
/// 得到站点用户ip
/// </summary>
/// <returns></returns>
public static string getuserip()
{
return httpcontext.current.request.servervariables["remote_addr"].tostring();
}

/// <summary>
/// 去除字符串最后一个','号
/// </summary>
/// <param name="chr">:要做处理的字符串</param>
/// <returns>返回已处理的字符串</returns>
public static string lost(string chr)
{
if (chr == null || chr == string.empty)
{
return "";
}
else
{
chr = chr.remove(chr.lastindexof(","));
return chr;
}
}

/// <summary>
/// 去除字符串第一个'/'号
/// </summary>
/// <param name="chr">要做处理的字符串</param>
/// <returns>返回已处理的字符串</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>
/// 替换html中的特殊字符
/// </summary>
/// <param name="thestring">需要进行替换的文本。</param>
/// <returns>替换完的文本。</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>
/// 恢复html中的特殊字符
/// </summary>
/// <param name="thestring">需要恢复的文本。</param>
/// <returns>恢复好的文本。</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>
/// 生成随机数字
/// </summary>
/// <param name="length">生成长度</param>
/// <returns></returns>
public static string number(int length)
{
return number(length, false);
}

/// <summary>
/// 生成随机数字
/// </summary>
/// <param name="length">生成长度</param>
/// <param name="sleep">是否要在生成前将当前线程阻止以避免重复</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;
}
1

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网