tagged [string.format]
String Interpolation in Visual Studio 2015 and IFormatProvider (CA1305)
String Interpolation in Visual Studio 2015 and IFormatProvider (CA1305) The new string interpolation style in Visual Studio 2015 is this: But if I use this the code analysis tells me I break [CA1305: ...
- Modified
- 19 Aug at 08:59
Use String.Format on a TimeSpan to output full seconds without milliseconds
Use String.Format on a TimeSpan to output full seconds without milliseconds I want to display the elapsed time between two dates in a string. Let's say I have the following code: What I expect:
- Modified
- 4 Apr at 05:57
Escaping arguments for string.Format in a C# multiline verbatim string
Escaping arguments for string.Format in a C# multiline verbatim string When I format it as a usual string with string.Format, naturally i get an exception that the input string was not in correct form...
- Modified
- 8 Oct at 19:31
How to do Alignment within string.Format in C#?
How to do Alignment within string.Format in C#? I have this line of code in C#: It draws its data from a text file and is output in a list box. I want to justify half of it to the left and half to the...
Is String.Format as efficient as StringBuilder
Is String.Format as efficient as StringBuilder Suppose I have a stringbuilder in C# that does this: would that be as efficient or any more efficient as having: If so, why
- Modified
- 20 Jan at 13:57
How to format TimeSpan to string before .NET 4.0
How to format TimeSpan to string before .NET 4.0 I am compiling in C# using .NET 3.5 and am trying to convert a TimeSpan to a string and format the string. I would like to use `myString = myTimeSpan.T...
- Modified
- 20 Jul at 12:7
How to Conditionally Format a String in .Net?
How to Conditionally Format a String in .Net? I would like to do some condition formatting of strings. I know that you can do some conditional formatting of integers and floats as follows: The above c...
- Modified
- 10 Mar at 15:13
String.Format vs ToString()
String.Format vs ToString() Can anyone explain if there is any benefit in either one of the following methods: Just to clarify, I'm not querying what the methods do, I'm obviously happy with that, jus...
- Modified
- 1 May at 15:40
How to use string.Format() to format a hex number surrounded by curly brackets?
How to use string.Format() to format a hex number surrounded by curly brackets? `uint hex = 0xdeadbeef;` `string result = "{deadbeef}"` First approach: Explicitly add the `{` and `}`; this works: Outp...
- Modified
- 20 Oct at 11:12
Need a custom currency format to use with String.Format
Need a custom currency format to use with String.Format I'm trying to use String.Format("{0:c}", somevalue) in C# but am having a hard time figuring out how to configure the output to meet my needs. H...
- Modified
- 12 Feb at 18:40
String.Format: Input string was not in a correct format
String.Format: Input string was not in a correct format The following code keep giving me error saying Input string was not in a correct format, but I am pretty sure it is right, isn't it? ``` int i...
- Modified
- 29 Jan at 00:35
Can I format NULL values in string.Format?
Can I format NULL values in string.Format? I was wondering if there's a syntax for formatting NULL values in string.Format, such as what Excel uses For example, using Excel I could specify a format va...
- Modified
- 7 Oct at 15:14
Localization of singular/plural words - what are the different language rules for grammatical numbers?
Localization of singular/plural words - what are the different language rules for grammatical numbers? I have been developing a .NET string formatting library to assist with localization of an applica...
- Modified
- 23 May at 12:16
Pad left or right with string.format (not padleft or padright) with arbitrary string
Pad left or right with string.format (not padleft or padright) with arbitrary string Can I use String.Format() to pad a certain string with arbitrary characters? ``` Console.WriteLine("->{0,18}{0,-18}...
- Modified
- 23 May at 10:30
String.Format exception when format string contains "{"
String.Format exception when format string contains "{" I am using VSTS 2008 + C# + .Net 2.0. When executing the following statement, there is FormatException thrown from String.Format statement, any ...
- Modified
- 15 Jul at 17:31