total number digit in string name.
-
Hello all gurus.. If I want to create the string that contains given digit like 3 for 3 digit in the string, how should i done it? To clear what I'm trying to say, here is an example. CString prefix = "pf"; int numDigit = 6; int startNum = 1; CString k; k.Format("%d%d",numDigit,startNum); k = prefix + k; the output that I want is: k = "pf0001" I know I'm doing it wrong.. coz the answer wasn't the one i want it and is there any other way instead of using for or while loop, counting numberDigit.
-
Hello all gurus.. If I want to create the string that contains given digit like 3 for 3 digit in the string, how should i done it? To clear what I'm trying to say, here is an example. CString prefix = "pf"; int numDigit = 6; int startNum = 1; CString k; k.Format("%d%d",numDigit,startNum); k = prefix + k; the output that I want is: k = "pf0001" I know I'm doing it wrong.. coz the answer wasn't the one i want it and is there any other way instead of using for or while loop, counting numberDigit.
-
Try this. It works.
CString prefix = "pf"; int numDigit = 6; int startNum = 1; CString k; k.Format("%0*d",numDigit-prefix.GetLength(),startNum); k = prefix + k; cout << (LPCTSTR) k;
Saving one line :D
CString prefix = "pf";
int numDigit = 6;
int startNum = 1;CString k;
k.Format("%s%0*d",prefix,numDigit-prefix.GetLength(),startNum);
cout << (LPCTSTR) k;Ivan Cachicatari www.latindevelopers.com
-
Saving one line :D
CString prefix = "pf";
int numDigit = 6;
int startNum = 1;CString k;
k.Format("%s%0*d",prefix,numDigit-prefix.GetLength(),startNum);
cout << (LPCTSTR) k;Ivan Cachicatari www.latindevelopers.com