本文主要为广大网友提供“字符串通用替换工具代码”,希望对需要字符串通用替换工具代码网友有所帮助,学习一下!
这是一个字符串通用替换工具代码,大家可以分析一下!
using System;
using System.Text;
using System.Text.RegularExpressions;
namespace My.Utils
{
/// <summary>
/// 字符串通用工具
/// </summary>
public class StringUtils
{
/// <summary>
/// 随机生成字符串源
/// </summary>
public const string RANDOM_STRING_SOURCE = "0123456789abcdefghijklmnopqrstuvwxyz";
public StringUtils()
{
}
/// <summary>
/// 替换字符串
/// </summary>
/// <param name="src">要修改的字符串</param>
/// <param name="pattern">要匹配的正则表达式模式</param>
/// <param name="replacement">替换字符串</param>
/// <returns>已修改的字符串</returns>
public static string Replace (string src, string pattern, string replacement)
{
return Replace(src, pattern, replacement, RegexOptions.None);
}
/// <summary>
/// 替换字符串,不区分大小写
/// </summary>
/// <param name="src">要修改的字符串</param>
/// <param name="pattern">要匹配的正则表达式模式</param>
/// <param name="replacement">替换字符串</param>
/// <returns>已修改的字符串</returns>
public static string ReplaceIgnoreCase (string src, string pattern, string replacement)
{
return Replace(src, pattern, replacement, RegexOptions.IgnoreCase);
}
/// <summary>
/// 替换字符串
/// </summary>
/// <param name="src">要修改的字符串</param>
/// <param name="pattern">要匹配的正则表达式模式</param>
/// <param name="replacement">替换字符串</param>
/// <param name="options">匹配模式</param>
/// <returns>已修改的字符串</returns>
public static string Replace (string src, string pattern, string replacement, RegexOptions options)
本新闻共3页,当前在第1页 1 2 3