[For VB.net]
Ok i have a number string that will be forever changing;
########
What is it in code to make that number string have commas in as a thousand seperator?
E.G
##,###,###
If you understand what i mean ![]()
-
-
Consert.ToString();
Then insert "," inside it
string S = "########";
string C = ",";Console.WriteLine(S.Insert(2,C));
If you need to go from right :
S.Substring(S.Length-"int NUMBER_OF_CHARS_FROM_RIGHT","int NUMBER_OF_CHARS_FROM_RIGHT")
S.Insert(S.Length-3,C); ( puts "," 3 chars from right|end ) -
There is a much better way.
Dim number As Integer = 1234567
Dim formattedString As String = number.ToString("#,#")
The big advantage is that this is locale aware. On my system I use the Dutch locale. We use periods as the thousand separators (and comma as the decimal separator, the exact reverse of what the US does). On my system, the above code will print 1.234.567 in accordance with my settings. On a US system it will print 1,234,567. And on a Indian system it will print 12,34,567 (they group by twos after the first group of three).
If you start with a string that needs formatting, first cast it to a number using Int32.Parse, Convert.ToInt32, or CInt, whichever you fancy. Or if you need floating point number Single.Parse, Convert.ToSingle or CSng. You get the idea.
Also see here: Custom numeric format strings. -
Thank you Sven Groot

-
OnErrorDoThis wrote:
Consert.ToString();
Then insert "," inside it
string S = "########";
string C = ",";Console.WriteLine(S.Insert(2,C));
If you need to go from right :
S.Substring(S.Length-"int NUMBER_OF_CHARS_FROM_RIGHT","int NUMBER_OF_CHARS_FROM_RIGHT")
S.Insert(S.Length-3,C); ( puts "," 3 chars from right|end )
This is why it isn't a witch hunt fella, while you are trying to be an active member and trying to help I think you may be jumping in too much and then you either give some poor advice or in terms of the coffee house.. just p' someone off..
Plus, as developers we're often highly prone to being perfectionists, and as you can imagine.. 'wars' break out
-
I found this guy's blog a few months ago and immediately printed out the .NET format strings cheat sheets.
Very handy since this stuff isn't always easy to remember.
http://john-sheehan.com/blog/index.php/net-cheat-sheets/ -
ScanIAm wrote:I found this guy's blog a few months ago and immediately printed out the .NET format strings cheat sheets.
Very handy since this stuff isn't always easy to remember.
http://john-sheehan.com/blog/index.php/net-cheat-sheets/
The MSDN resource:
http://msdn2.microsoft.com/en-us/library/26etazsy.aspx
Look at the bottom in the See Also section. Full details. -
odujosh wrote:

ScanIAm wrote:
I found this guy's blog a few months ago and immediately printed out the .NET format strings cheat sheets.
Very handy since this stuff isn't always easy to remember.
http://john-sheehan.com/blog/index.php/net-cheat-sheets/
The MSDN resource:
http://msdn2.microsoft.com/en-us/library/26etazsy.aspx
Look at the bottom in the See Also section. Full details.
Yeah. This came up in a thread a few years ago. The MSDN site does, probably, have more information, but it took me at least 2 clicks, and I had a couple of false starts before I found a list of date format strings.
What I like about the format strings cheat sheet is that it's a 4 page PDF that simply lists out what each one does.
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.