📄 common.cs
字号:
using System;
using System.Web;
using System.Text.RegularExpressions;
namespace liuwei.FrameWork
{
/// <summary>
/// 摘要说明。
/// </summary>
public class Common
{
public Common()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static string GetUserIpAddress(HttpContext context)
{
string result = String.Empty;
if (context == null) return result;
result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (null == result || result == String.Empty)
result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
return result;
}
public static string CheckForUrl(string text)
{
if(text == null || text.Trim().Length == 0 || text.Trim().ToLower().StartsWith("http://"))
{
return text;
}
return "http://" + text;
}
public static string SafeFormat(string stringToTransform)
{
stringToTransform = HttpContext.Current.Server.HtmlEncode(stringToTransform);
return stringToTransform.Replace("\n", "<br>");
}
public static string SafeFormatWithUrl(string stringToTransform)
{
return EnableUrls(SafeFormat(stringToTransform));
}
public static string EnableUrls(string text)
{
string pattern = @"(http|ftp|https):\/\/[\w]+(.[\w]+)([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])";
MatchCollection matchs;
matchs = Regex.Matches(text,pattern, RegexOptions.IgnoreCase | RegexOptions.Compiled);
foreach (Match m in matchs)
{
text = text.Replace(m.ToString(), "<a target=\"_new\" href=\"" + m.ToString() + "\">" + m.ToString() + "</a>");
}
return text;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -