0

I want to find replace Version number from a string by using Regex in c#.

string is like this:

string val="AA.EMEA.BizTalk.GroupNettingIntegrations, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a86ac114137740ef";

Is any one can help me to solve this problem.

1
  • That doesn't really make much sense about what you are trying to do, please be more specific Commented Aug 24, 2011 at 14:50

2 Answers 2

2

It seems to me you could easily accomplish this without a regex and have your code be easier to read:

 string components[] = someAssemblyFullyQualifiedName.Split(new char[] { ',' }, StringSplitOptions.IgnoreEmptyEntires);

 if(components.Length > 1)
    components[1] = "Version=2.0.0.0"; // whatever you want to replace with

 string newFullyQualifiedName = string.Join(",", components):
Sign up to request clarification or add additional context in comments.

1 Comment

Was going to suggest something similar, you beat me to it (though you dont need to supply the "new char[] { ',' }" bit, just ',' is sufficient)
1

The following Regex will do the replace you are looking for.

string val = "AA.EMEA.BizTalk.GroupNettingIntegrations, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a86ac114137740ef";
val = Regex.Replace(val, @"Version=[\d\.]+", "Version=2.0.0.0");

EDIT: You can also use look-behind Regex functionality if you don't want to have to put the "Version=" in the replacement string. If you are looking for that, add a comment and I'll draw it up.

2 Comments

val = Regex.Replace(val, @"Version=[\d\.]+", "Version=2.0.0.0"); it should be like this.
I'd use (\d+\.)(\d+\.)(\d+\.)(\d+) instead to be more precise for the regular expression. In yours you could allow "2." or whatever.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.