📄 linkparser.cs
字号:
namespace Imps.Client.Core
{
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
public class LinkParser
{
private static string _regex = @"(((http|https|ftp)\://)([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&%\$\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\?\'\\\+&%\$#\=~_\-]+))*)|(www.([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&%\$\-]+)*@)*(([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\?\'\\\+&%\$#\=~_\-]+))*)";
private List<pair<object, SizeF>> m_richtext = new List<pair<object, SizeF>>();
public static List<object> ParseString(string strInput)
{
List<object> list = new List<object>();
if (!string.IsNullOrEmpty(strInput))
{
MatchCollection matchs = new Regex(_regex, RegexOptions.IgnoreCase).Matches(strInput);
string text = string.Empty;
if (matchs.Count == 0)
{
list.Add(strInput);
return list;
}
for (int i = 0; i < matchs.Count; i++)
{
if (i == 0)
{
if (matchs[i].Index != 0)
{
text = strInput.Substring(0, matchs[i].Index);
list.Add(text);
}
}
else if ((matchs[i - 1].Length + matchs[i - 1].Index) != matchs[i].Length)
{
text = strInput.Substring(matchs[i - 1].Length + matchs[i - 1].Index, matchs[i].Index - (matchs[i - 1].Length + matchs[i - 1].Index));
list.Add(text);
}
rich_string_link _link = new rich_string_link(matchs[i].ToString());
list.Add(_link);
if ((i == (matchs.Count - 1)) && ((matchs[i].Index + matchs[i].Length) < strInput.Length))
{
text = strInput.Substring(matchs[i].Index + matchs[i].Length);
list.Add(text);
}
}
}
return list;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -