Problem Formatting A String

  • Thread starter Thread starter CCLeasing
  • Start date Start date
C

CCLeasing

I'm trying to format a string, using placeholders. I have tried the
following : -

String Time = string.Format("Time: (({0 - {1}}))", txtDate.Text,
txtTime.Text);
MessageBox.Show(Time);

The string i'm trying to achieve would look something like this : -

Time: ((1/1/06 - 12:32))

but i'm getting the error that 'input string was not in the correct
format)

can someone advise,

Many Thanks.
 
Hi,

Try the following string:

"Time: (({0} - {1}))"

The {0} token indicates a replacement with the parameter at index 0 (zero).
{1} indicates a replacement with the parameter at index 1.
 
CCLeasing said:
String Time = string.Format("Time: (({0 - {1}}))", txtDate.Text,
txtTime.Text);

It screws with your eyes if you stare too hard, but your braces have
become mismatched :- the closing brace of the {0} seems to have gone
for a walk, round to the other side of the {1}. Presumably you've done
{0} first and then added {1} later?
 
Back
Top