TomiTeruz TomiTeruz - 2 months ago 5
C# Question

find character format and replace in c#

How to find character format and replace in c#

I wanna find this in string

x[number].


My code

string input = "23. 11x10.9.1.10x03.9x8"
string okk;
Regex ini = new Regex(input, @"\d");
string lol = "x"+ini+".";
txtOutput.Text = input.Replace(lol, " ");


i hope replace to

txtOutput --> "23.11x10. 9.1.10x03. 9x8. "

Answer

In 23. 11x10.9.1.10x03.9x8

Out 23.11x10. 9.1.10x03. 9x8

string input = "23. 11x10.9.1.10x03.9x8";
input = input.Replace(" ", ""); //del blank character
Regex ini = new Regex(@"\d+"); //1-n Numbers
Match match = ini.Match(input);
string lol = "";
while (match.Success) { 
     lol = "x" + match.Value + ".";
     input = input.Replace(lol, lol + " ");
     match = match.NextMatch();
}   

input = input + ". "; //attached . and space, after last character

MessageBox.Show(input);
Comments