0

Basically I have a http address that I would like to change with {0} within the string from a variable. Is there a key I can quickly use to do this? thanks

my code is

string ticker;
string url=("http://localhost:8080/SetOutput?symbol={0}&feedtype=breath&output={ sigma}&status=on", ticker);

Update: Understand this has been answered before. Figured as my string "ticker" was the same color code as the rest of the string URL, it wasn't being recognized as a variable.

Luke Zhang
  • 343
  • 1
  • 4
  • 14
  • `url = string.Format(url, text);` where text is your variable. – ManoDestra May 24 '16 at 00:23
  • Hi Luke729! Sorry that your question has been downvoted a couple times. The reason it was likely downvoted was because this question has already been answered. Before submitting new questions to Stack Overflow, be sure to check the previously asked questions, first. – kayleeFrye_onDeck May 24 '16 at 04:04

2 Answers2

1

You might be looking for string.Format(inputString, params[]) You could have:

string ticker = "googl"; //Google
string url=string.Format("http://localhost:8080/SetOutput?symbol={0}&feedtype=breath&output={ sigma}&status=on", ticker);
Goran Mottram
  • 6,244
  • 26
  • 41
Jon Helms
  • 177
  • 10
  • This code can produce invalid url. Please avoid doing so - see http://stackoverflow.com/questions/829080/how-to-build-a-query-string-for-a-url-in-c for proper way of doing it. – Alexei Levenkov May 24 '16 at 02:08
0

You could use string.Format as Jon has said or you could also use a C#6 feature if your running Visual Studio 2015.

string name="xela";
string url = $"http://www.foo.com?name={name}";
Xela
  • 2,322
  • 1
  • 17
  • 32