formatlist.cs
来自「本系统是在asp版《在线文件管理器》的基础上设计制作」· CS 代码 · 共 76 行
CS
76 行
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Collections.Specialized;
using System.Text.RegularExpressions;
namespace CommunityServer.Components
{
/// <summary>
/// Summary description for EmailFormatList.
/// </summary>
public class FormatList
{
public FormatList()
{
//
// TODO: Add constructor logic here
//
}
//Internal collection
NameValueCollection nvc = new NameValueCollection();
/// <summary>
/// Adds a new Formatting to the internal collection
/// </summary>
/// <param name="name"></param>
/// <param name="value"></param>
public void Add(string name, string value)
{
nvc.Add(FormatName(name),value);
}
/// <summary>
/// Helper method used to apply regex formatting to our name value
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
private static string FormatName(string name)
{
return string.Format(@"\[{0}\]", name);
}
/// <summary>
/// Iterates over the internal collection and applies the new formattings
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
public string Format(string text)
{
if(nvc.Count == 0)
return text;
foreach(string key in nvc.AllKeys)
{
string value = nvc[key];
if(value != null)
text = Regex.Replace(text, key, value , RegexOptions.IgnoreCase | RegexOptions.Compiled);
}
return text;
}
public static string Format(string input, string name, string text)
{
return Regex.Replace(input, FormatName(name), text , RegexOptions.IgnoreCase | RegexOptions.Compiled);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?