Answer the question
In order to leave comments, you need to log in
Doubling digits in c# how?
Still practicing with text documents.
How to use a regular expression to replace multiple digits?
For example I have the following:
string result = Regex.Replace(line,@"1$", @"111").Replace(@"2$", @"222");
Console.WriteLine(result);
Answer the question
In order to leave comments, you need to log in
Regex.Replace returns the string on which you call the Replace method, which has nothing to do with Regex.
You need to understand C# a little more.
Templates for replacing numbers with others and etc. are googled, with difficulty, but googled. On kraynyak there is documentation that will have to be read.
Use extension methods:
using System.Text.RegularExpressions;
public static class RegexEx
{
public static string ReplaceEx(this string input, string pattern, string replacement)
{
return Regex.Replace(input, pattern, replacement);
}
}
string line = "123";
string result = line.ReplaceEx("1", "111").ReplaceEx("2", "222").ReplaceEx("3", "333");
Console.WriteLine(result); // 111222333
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question