1

Trying to pass the values but not making progress.

Scenario : Have a public constant string as below.

public const string ImageFile = @"http://xyz.com/scom/{0}?type={1}&wid={2}"; 

I will then get the relevant values required for 0,1,2 that is required for above.

Question is how do I pass the values I have for 0,1,2 to the above const string?

My end result should be something like

string mySTring = "http://xyz.com/scom/123?type=jpg&wid=200" 

Please suggest.

Thanks.

3
  • 8
    How did you know the syntax for string.Format (i.e. {0}) without knowing about string.Format? Commented May 16, 2012 at 20:21
  • 1
    @KirlWoll - Methods like Console.WriteLine allow for composite formatting. In other words, string.format can be used implicitly in many if not most cases. Many developers can use string.format and never even know it. msdn.microsoft.com/en-us/library/txafckwd.aspx Commented May 16, 2012 at 20:27
  • I once encountered a major performance issue because someone knew all about vfprintf, but had no idea sprintf existed... Commented May 16, 2012 at 20:34

2 Answers 2

9

Using String.Format:

string ActualImageFile = String.Format(ImageFile, param1, param2, param3); 
Sign up to request clarification or add additional context in comments.

Comments

3
string.Format(@"http://xyz.com/scom/{0}?type={1}&wid={2}", param1, param2, param3); 

Should do the trick.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.