Permalink
Cannot retrieve contributors at this time
Fetching contributors…
| // <Snippet3> | |
| using System; | |
| using System.Text.RegularExpressions; | |
| public class Example | |
| { | |
| public static void Main() | |
| { | |
| string pattern = @"^(\w+\s?)+$"; | |
| string[] titles = { "A Tale of Two Cities", | |
| "The Hound of the Baskervilles", | |
| "The Protestant Ethic and the Spirit of Capitalism", | |
| "The Origin of Species" }; | |
| string replacement = "\"$&\""; | |
| foreach (string title in titles) | |
| Console.WriteLine(Regex.Replace(title, pattern, replacement)); | |
| } | |
| } | |
| // The example displays the following output: | |
| // "A Tale of Two Cities" | |
| // "The Hound of the Baskervilles" | |
| // "The Protestant Ethic and the Spirit of Capitalism" | |
| // "The Origin of Species" | |
| // </Snippet3> |