I've a predefined string format. For instance '>>>,>>>,>>9.99' this means that the system should display string in this '500,000,000.10'. The format can change based on the users using it. How can I write a common function to display stings on the given format passing the input value and the format as the parameter using C#
8 Answers
For example:
string format = "{0:000,000,000.00}";
string val = 12.3456;
Console.WriteLine(string.Format(format, value)); // it prints "000,000,123.23"
You can read more about formating values here http://www.csharp-examples.net/string-format-double/
Comments
String.formate can be used for formating.
Go there if you want examples http://www.csharp-examples.net/string-format-double/
Comments
There is a Format method on String.
String.Format("{0:X}", 10); // prints A (hex 10)
Comments
I dont seem to understand how you can make 500,000,000.10 from >>>,>>>,>>9.99' but I believe the answer would be
But I assume something you are looking for is: string.Format("500,000,00{0:0.##}", 9.9915)
You can then make a method like
Public string GetString(string Format, object value)
{
return string.Format(Format, value);
}
Something like this?
2 Comments
Xander
why would you need a "GetString" method to call string.format with the exact same parameters?
Theun Arbeider
because the TS asked how to write a common function.