I am formatting a date:
str = String.Format("{0:MMM d m:mm"+yearStr+"}", dt);
I want to put the word "at" after the "d", but I don't want the string to format it. I just want the word "at".
How can I achieve this?
To escape % , you will need to double it up: %% .
In Ruby we apply the string format syntax (the "%" operator) to ease this creation of formatted string data. After the "%" we specify arguments. A first example. We use the percentage sign ("%") to specify a format code within a string.
"; C# includes escaping character \ (backslash) before these special characters to include in a string. Use backslash \ before double quotes and some special characters such as \,\n,\r,\t, etc. to include it in a string.
You can surround literal strings with quotes, which for longer strings is probably easier and a bit more readable than escaping every character with a backslash:
str = String.Format("{0:MMM d 'at' m:mm"+yearStr+"}", dt);
See Custom Date and Time Format Strings in MSDN Library (search for "Literal string delimiter").
(And did you mean h:mm
instead of m:mm
?)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With