ba*****@optonline.net (Babu Mannaravalappil) wrote in
news:35**************************@posting.google.c om:
Hi,
I want to replace some words in my text files (actually
transpose). For example, I have a whole lot of expressions
(words) in my files as follows:
TABLECUSTOMERS
TABLEORDERS
TABLEORDERLINES
I want to replace them as follows:
CUSTOMERSTABLE
ORDERSTABLE
ORDERLINESTABLE
How can I do this using regular expression search and repalce?
Babu,
Use a pattern of "\bTABLE(.*?)\b", and a replacement string of
"$1TABLE".
Here's an example in C#:
using System;
using System.Text.RegularExpressions;
namespace Main
{
public class MainClass
{
[STAThread]
public static int Main()
{
string input = @"
TABLECUSTOMERS
TABLEORDERS
TABLEORDERLINES
";
Console.WriteLine(SwapWords(input, "TABLE"));
return 0;
}
public static string SwapWords(
string input,
string word)
{
return Regex.Replace(input, "\\b" + word + "(.*?)\\b",
"$1" + word, RegexOptions.Singleline);
}
}
}
--
Hope this helps.
Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/