CString to Numeric Value
-
-
Hi All does any one know what would be the best way to convert a CString containing only characters to a numeric value. for example CString str = "AFG" output to be say int 653790; and each time you convert the str, you get the same result Thanks Si :)
si_69 wrote: CString str = "AFG" output to be say int 653790; Do you want a hash value of the string, or simply want each character in the CString to be converted to its ASCII value? * Artificial intelligence is no match for natural stupidity! *
-
Hi All does any one know what would be the best way to convert a CString containing only characters to a numeric value. for example CString str = "AFG" output to be say int 653790; and each time you convert the str, you get the same result Thanks Si :)
Did you try atoi or _atoi64 ? MS
-
si_69 wrote: CString str = "AFG" output to be say int 653790; Do you want a hash value of the string, or simply want each character in the CString to be converted to its ASCII value? * Artificial intelligence is no match for natural stupidity! *
-
Did you try atoi or _atoi64 ? MS
-
Manfred Staiger wrote: Did you try atoi or _atoi64 ? yes, both return 0 i have lots of character ID's such as 'AB', 'POL', 'AA' etc i need to convert them to unique values
What about converting each character of the string to it's ASCII code (__toascii) assemble the results to a number ? I hope you understand what I mean, my english is not the best. MS
-
Nirav Doshi wrote: Do you want a hash value of the string, or simply want each character in the CString to be converted to its ASCII value? yeah i would need for each character in the CString to be converted to its ASCII values thanks
A simple function would do for that!
CString GetASCIICodedString(CString& srcString) { CString srcResult, srcBuffer; for(int nIndex = 0; nIndex < srcString.GetLength(); nIndex++) { srcBuffer.Empty(); srcBuffer.Format("%d", srcString.GetAt(nIndex)); srcResult += srcBuffer; } return srcResult; }
This should work... I've not compiled it, just some rough code, so please test it properly. * Artificial intelligence is no match for natural stupidity! *
-
A simple function would do for that!
CString GetASCIICodedString(CString& srcString) { CString srcResult, srcBuffer; for(int nIndex = 0; nIndex < srcString.GetLength(); nIndex++) { srcBuffer.Empty(); srcBuffer.Format("%d", srcString.GetAt(nIndex)); srcResult += srcBuffer; } return srcResult; }
This should work... I've not compiled it, just some rough code, so please test it properly. * Artificial intelligence is no match for natural stupidity! *
Is possible, please let me know if this helped, or if it gave you any further problems! * Artificial intelligence is no match for natural stupidity! *
-
A simple function would do for that!
CString GetASCIICodedString(CString& srcString) { CString srcResult, srcBuffer; for(int nIndex = 0; nIndex < srcString.GetLength(); nIndex++) { srcBuffer.Empty(); srcBuffer.Format("%d", srcString.GetAt(nIndex)); srcResult += srcBuffer; } return srcResult; }
This should work... I've not compiled it, just some rough code, so please test it properly. * Artificial intelligence is no match for natural stupidity! *
srcBuffer.Empty();
seems extraneous. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com