Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Explain String.Format 1

Status
Not open for further replies.

kav123

Programmer
Jan 12, 2005
210
GB
Can someone explain what String.Format does. Basically i am amending someone's code and they have used String.Format to append parameters to the url. I need to basically add another parameter to that url.

here is the code, hope someone helps me with this one:

emailLink.NavigationUrl = ResolveUrl(string.Format("~/QuoteMonitor/QuoteMonitor.aspx?{0}={1}", QueryStringItemNames.QuoteMonitorStatusName, string.Format("byEmail${0}", quote.EmailAddress)));

byEmail is the querystring name and q'quote.EmailAddress' is the value. So currently it passes email and the email address. I need to add another name/value pair to this url with this parameter already there.
 
string.format does what is says. the {#} is a place holder for the respective parameter after the string. depending on the type of value you can format the parameter within {}
the string above would be easier to read like this
Code:
string key = QueryStringItemNames.QuoteMonitorStatusName;
string link = string.Format("~/QuoteMonitor/QuoteMonitor.aspx?{0}=byEmail${1}", key, quote.EmailAddress);
emailLink.NavigationUrl = ResolveUrl(link);

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Ok, got that but how do i add another parameter to this url, i.e. another key/value pair.
 
example:
string.format("{0}{1}{2}{3}", 1,"foo",DateTime.Now,new object());

the signature is string.format(string template, params string[] args);
params is the key here as you can add a variable amount of arguments.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Hey thanks so much for that, that was really helpful. You are a star,.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top