Regex HelperReplace Pattern 方法
使用缓存编译的正则表达式替换匹配项。
Definition
命名空间: Suresking.Utility
程序集: Suresking.Utility (在 Suresking.Utility.dll 中) 版本:1.3.22+a27276bb8ffde055e69ff608e98aafba279e1e99
替换后的字符串。
程序集: Suresking.Utility (在 Suresking.Utility.dll 中) 版本:1.3.22+a27276bb8ffde055e69ff608e98aafba279e1e99
C#
public static string ReplacePattern(
string input,
string pattern,
string replacement,
RegexOptions options = RegexOptions.None
)参数
- input String
- 要执行替换的源字符串。
- pattern String
- 正则表达式模式,不能为 null 或空。
- replacement String
- 替换字符串。
- options RegexOptions (Optional)
- 正则表达式选项。
返回值
String替换后的字符串。
示例
C#
string result = RegexHelper.ReplacePattern("Hello World", @"\s+", "-");
// result = "Hello-World"异常
| ArgumentNullException | input 或 replacement 为 null。 |
| ArgumentException | pattern 为 null 或空。 |