0

I have this string.

string str = "5595176&cn=ANY&ln=ADdedfr";

I need to replace ANY to 12345

string str = "5595176&cn=12345&ln=ADdedfr

string ANY may be different.

halfer
  • 19,824
  • 17
  • 99
  • 186
Igor Strekha
  • 176
  • 3
  • 17
  • I wan't to replace any, any can be different..? Is it always prefixed by cn=? And do you have to use ragex? Why not split and replace or something. Also does any always have the same length? How do we know what to replace if it can be different. – EpicKip Jan 27 '17 at 08:00
  • @MohitShrivastava But any can be different it says, that's why you need more information :) but regex doesn't sound necessary here though. – EpicKip Jan 27 '17 at 08:08
  • I have JS solution)) Please look at – Igor Strekha Jan 27 '17 at 08:09
  • link = link.replaceAll("cn=[A-Za-z]+", "cn=" + countryCode); – Igor Strekha Jan 27 '17 at 08:10

1 Answers1

1

This might do the trick for you

using System.Text.RegularExpressions;
string mystr = Regex.Replace(str, "cn=[A-Za-z]+", "cn=12345");

According to the comment it could be

using System.Text.RegularExpressions;
string mystr = Regex.Replace(str, "cn=[A-Za-z]+", "cn=" + CountryCode);
Mohit S
  • 13,723
  • 6
  • 34
  • 69