Home > Back-end >  How can I replace part of string by position to the end of the string?
How can I replace part of string by position to the end of the string?

Time:03-17

If i have a string

"https://test.local.com/{version}/123456

I want to replace {version}/123456 with v50.0

How can i do that ?

CodePudding user response:

Following is the possible solution.

string url = "https://test.local.com/{version}/123456";
int versionIndex = url.IndexOf("{version}");
string output = url;
if(versionIndex >= 0)
{
 output = url.Substring(0,versionIndex)   "v50.0";
}
  •  Tags:  
  • c#
  • Related