String

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I am using replacing a parameter into a string as follows:

string.Format("var Tracker = getTracker(\"{0}\");", account));

If account is, for example, 123I get:
var Tracker = getTracker("123");

But if account is null I get:
var Tracker = getTracker("");

In this case I would like to get this without the quotes. Just:
var Tracker = getTracker();

Can I do this without the need to wrap my code line inside an "if" ?

Thanks,
Miguel
 
I am using replacing a parameter into a string as follows:

string.Format("var Tracker = getTracker(\"{0}\");", account));

If account is, for example, 123I get:
var Tracker = getTracker("123");

But if account is null I get:
var Tracker = getTracker("");

In this case I would like to get this without the quotes. Just:
var Tracker = getTracker();

Can I do this without the need to wrap my code line inside an "if" ?

Yes:
string.Format("var Tracker = getTracker({0});",
account == null ? "" : "\"" + account + "\"")

Jon
 
I am using replacing a parameter into a string as follows:

string.Format("var Tracker = getTracker(\"{0}\");", account));

If account is, for example, 123I get:
var Tracker = getTracker("123");

But if account is null I get:
var Tracker = getTracker("");

In this case I would like to get this without the quotes. Just:
var Tracker = getTracker();

Can I do this without the need to wrap my code line inside an "if" ?

Yes:
string.Format("var Tracker = getTracker({0});",
account == null ? "" : "\"" + account + "\"")

Jon
 
Back
Top