用Regex.Replace() 参考 // This code example demonstrates the System.Text.Regular- // Expressions.Regex.Replace(String, String) method.using System; using System.Text.RegularExpressions;class Sample { public static void Main() { // Create a regular expression that matches a series of one // or more white spaces. string pattern = @"\s+"; Regex rgx = new Regex(pattern);// Declare a string consisting of text and white spaces. string inputStr = "a b c d";// Replace runs of white space in the input string with a // comma and a blank. string outputStr = rgx.Replace(inputStr, ", ");// Display the resulting string. Console.WriteLine("Pattern: \"{0}\"", pattern); Console.WriteLine("Input string: \"{0}\"", inputStr); Console.WriteLine("Output string: \"{0}\"", outputStr); } } /* This code example produces the following results:Pattern: "\s+" Input string: "a b c d" Output string: "a, b, c, d"*/
参考
// This code example demonstrates the System.Text.Regular-
// Expressions.Regex.Replace(String, String) method.using System;
using System.Text.RegularExpressions;class Sample
{
public static void Main()
{
// Create a regular expression that matches a series of one
// or more white spaces.
string pattern = @"\s+";
Regex rgx = new Regex(pattern);// Declare a string consisting of text and white spaces.
string inputStr = "a b c d";// Replace runs of white space in the input string with a
// comma and a blank.
string outputStr = rgx.Replace(inputStr, ", ");// Display the resulting string.
Console.WriteLine("Pattern: \"{0}\"", pattern);
Console.WriteLine("Input string: \"{0}\"", inputStr);
Console.WriteLine("Output string: \"{0}\"", outputStr);
}
}
/*
This code example produces the following results:Pattern: "\s+"
Input string: "a b c d"
Output string: "a, b, c, d"*/
查找:<A_B>[]*</A_B>
替换为:%01%03
假设原始文件为:
有个xml文件
有大量的 <A_B>aaaaaa </A_B>
我想用正则把所有
<A_B> 中间的部分替换掉
该怎么写呢? 谢谢
将被转换为:
有个xml文件
有大量的 <A_B></A_B>
我想用正则把所有
<A_B> 中间的部分替换掉
该怎么写呢? 谢谢