How to zero-pad a number?
-
And the second?
PIEBALDconsult wrote:
And the second?
Doesn't matter. The documentation clearly states, "When one or both operands are of type string...", so the type of the other operand is irrelevant.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
PIEBALDconsult wrote:
And the second?
Doesn't matter. The documentation clearly states, "When one or both operands are of type string...", so the type of the other operand is irrelevant.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
I missed that the first time also. :)
BDF The internet makes dumb people dumber and clever people cleverer. -- PaulowniaK
-
PIEBALDconsult wrote:
And the second?
Doesn't matter. The documentation clearly states, "When one or both operands are of type string...", so the type of the other operand is irrelevant.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Where do you see that in the documentation? I don't even see
+
in the documentation. And what idiot thought that was a good idea? :wtf: Time to find a new language; this one's becoming VB. X| Edit: I finally found it; it's not documented with String; what a POS. :thumbsdown: I'm fairly sure that no self-respecting C# professional uses it that way. -
Where do you see that in the documentation? I don't even see
+
in the documentation. And what idiot thought that was a good idea? :wtf: Time to find a new language; this one's becoming VB. X| Edit: I finally found it; it's not documented with String; what a POS. :thumbsdown: I'm fairly sure that no self-respecting C# professional uses it that way.It's the link that I posted in my previous message: http://msdn.microsoft.com/en-GB/library/k1a63xkz.aspx[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Where do you see that in the documentation? I don't even see
+
in the documentation. And what idiot thought that was a good idea? :wtf: Time to find a new language; this one's becoming VB. X| Edit: I finally found it; it's not documented with String; what a POS. :thumbsdown: I'm fairly sure that no self-respecting C# professional uses it that way.PIEBALDconsult wrote:
I'm fairly sure that no self-respecting C# professional uses it that way.
Heh, I go for the shorter version. If it doesn't make sense with a mishmash of ints/strings I use brackets or ToString(). Like for:
int i = 124, j = 253;
string s = "JD" + i + j; // Could be two things and no one wants to look up operator precedence, so instead...
string t = "JD" + (i + j);But yeah, usually I don't bother. Although, theoretically, I could now do
string s = 0; // won't initialise
string t = "" + 0; // will work fine O.oSo, let's get back to self-respecting... :rolleyes:
-
Where do you see that in the documentation? I don't even see
+
in the documentation. And what idiot thought that was a good idea? :wtf: Time to find a new language; this one's becoming VB. X| Edit: I finally found it; it's not documented with String; what a POS. :thumbsdown: I'm fairly sure that no self-respecting C# professional uses it that way.PIEBALDconsult wrote:
I'm fairly sure that no self-respecting C# professional uses it that way.
Heh, I go for the shorter version. If it doesn't make sense with a mishmash of ints/strings I use brackets or ToString() to clarify.
int i = 124, j = 253;
string s = "JD" + i + j; // Could be two things and no one wants to look up operator precedence, so instead...
string t = "JD" + (i + j);But yeah, usually I don't bother. Although, theoretically, I could now do
string s = 0; // won't initialise
string t = "" + 0; // will work fine O.oSo, let's get back to self-respecting... :rolleyes:
-
PIEBALDconsult wrote:
I'm fairly sure that no self-respecting C# professional uses it that way.
Heh, I go for the shorter version. If it doesn't make sense with a mishmash of ints/strings I use brackets or ToString() to clarify.
int i = 124, j = 253;
string s = "JD" + i + j; // Could be two things and no one wants to look up operator precedence, so instead...
string t = "JD" + (i + j);But yeah, usually I don't bother. Although, theoretically, I could now do
string s = 0; // won't initialise
string t = "" + 0; // will work fine O.oSo, let's get back to self-respecting... :rolleyes:
string t = System.String.Format ( "JD{0}" , i + j ) ;
-
string t = System.String.Format ( "JD{0}" , i + j ) ;
Make that:
string t = string.Format(CultureInfo.InvariantCulture, "JD{0:D}", i + j);
You typically don't want culture-specific formatting or group separators in the result.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Make that:
string t = string.Format(CultureInfo.InvariantCulture, "JD{0:D}", i + j);
You typically don't want culture-specific formatting or group separators in the result.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
I've never had that problem.
-
Make that:
string t = string.Format(CultureInfo.InvariantCulture, "JD{0:D}", i + j);
You typically don't want culture-specific formatting or group separators in the result.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
A padded number in a file name!
// Set to padded number
int fileCount = Directory.GetFiles("[censored]", "*.csv", SearchOption.AllDirectories).Length + 1;
string fileCountStr = (fileCount <= 999 ? fileCount <= 99 ? fileCount <= 9 ? "000" : "00" : "0" : "") + fileCount;I think this should win an award for readability in a triply-nested ternary condition :rolleyes:.