From primitive type to string
-
I want to know the algorithm used to make a string from an integer, double, etc., to a string and the other way around. Does anyone know this algorithm, I need to use this, because I'm making a garbage collected (Boehm-Weiser) string wrapper for use with TCHAR. Thanks in advance, Sjoerd van Leent LPCTSTR Dutch = TEXT("Double Dutch :-)");
-
I want to know the algorithm used to make a string from an integer, double, etc., to a string and the other way around. Does anyone know this algorithm, I need to use this, because I'm making a garbage collected (Boehm-Weiser) string wrapper for use with TCHAR. Thanks in advance, Sjoerd van Leent LPCTSTR Dutch = TEXT("Double Dutch :-)");
Maybe you can have a look at the source code for
itoa
and related files. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo -
Maybe you can have a look at the source code for
itoa
and related files. Joaquín M López Muñoz Telefónica, Investigación y DesarrolloLogical, but I need to have the source files to do that, as far as I know, these files are all libraries, that's kinda problem. Sjoerd van Leent LPCTSTR Dutch = TEXT("Double Dutch :-)");
-
Logical, but I need to have the source files to do that, as far as I know, these files are all libraries, that's kinda problem. Sjoerd van Leent LPCTSTR Dutch = TEXT("Double Dutch :-)");
Maybe it depends on the installation, but at leat in mine the source code is under Microsoft Visual Studio/VC98/CRT/SRC Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
Maybe it depends on the installation, but at leat in mine the source code is under Microsoft Visual Studio/VC98/CRT/SRC Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
You're right, I can find it. I looked it somewhat and made my own code doing it. I've just finished the String to Integer algorithm.
int String::ToInteger(String string) { size_t index = 0; bool leadSpace = true; bool isValue = true; bool minus = false; int value = 0; try { // first scanning if the string has non-numbers while(leadSpace) { TCHAR tcRet = string.GetCharAt(index); if (((tcRet < TEXT('0')) || (tcRet > TEXT('9')) ) && (tcRet != TEXT('-')) && (tcRet != TEXT('+'))) { index++; } else { leadSpace = false; } } // scan whether the first character is equal to '-' (45) or '+' (43) TCHAR tcRet = string.GetCharAt(index); if (tcRet == TEXT('-')) { minus = true; index++; } else if (tcRet == TEXT('+')) { index++; } // OK, now a number begins, I hope, if no number is found after the minus // or plus sign, we immediatly return 0 while (isValue) { TCHAR tcRet = string.GetCharAt(index); if (tcRet >= TEXT('0') && tcRet <= TEXT('9')) { int hold = (int)tcRet - (int)TEXT('0'); value *= 10; value += hold; index++; } else { if (minus) return -value; else return value; } } } catch (Exception ex) { throw (ex); } return 0; }
this is the code I'm using now to do it (if someone likes it, just use it) I'm now working on ToDouble, ToBoolean (easy!), ToUnsignedInteger, etc... Sjoerd van Leent LPCTSTR Dutch = TEXT("Double Dutch :-)");