Reputation: 1479
I have a date with weeks using this format:
2012-15 - 2012-20
I want to format it to look like
2012 v15 - 2012 v20
How can this be done c#?
Upvotes: 0
Views: 693
Reputation: 16524
Try this:
string input = "2012-15 - 2012-20";
string output = Regex.Replace(input, @"(\d{4})-(\d+)", "$1 v$2");
Upvotes: 1
Reputation: 25619
string input = "2012-15 - 2012-20";
string output = Regex.Replace(input, @"\b(-)\b", "v");
Upvotes: 0
Reputation: 52185
This should do the trick:
String str = "2012-15 - 2012-20";
String newStr = Regex.Replace(str, "(\\d+)-(\\d+)", "$1 v$2");
Console.WriteLine(str);
Console.WriteLine(newStr);
Console.ReadLine();
Prints Out:
2012-15 - 2012-20
2012 v15 - 2012 v20
Upvotes: 3