August 10th, 2003, 11:35 AM
How can I get Label1->Text To Integer or the length of Label1->Text
I use VC++ .net, bad for me StrToInt is not working:mad:
How can I convert Label1->Text to Integer or the length of Label1->Text?
August 10th, 2003, 01:13 PM
I don't really know what your talking about?
If you want to convert string to integer, like "1016" to 1016, look at the function below, if you want to convert num to string, like 1016 to "1016", look at wsprintf(). GetWindowTextLength gets the length of text in a window. strlen() can be used to get length of a string.
int s2n(char *str)
//accept a string, and return the number ("1016" will be 1016.. works for negative)
int neg=(str=='-')?1:0; //1==neg,0==pOs
for(;--len>=neg;n+=(str[len]-'0')*base,base*=10) //Compact :)
if(str[len] > '9' || str[len] < '0')
return neg ? n * -1 : n; //if negative, times by -1
August 10th, 2003, 01:20 PM
If what you want is the value represented by the string you could use the atoi : (C)
int atoi(const char *s).
August 10th, 2003, 03:47 PM
In C++ .NET you can convert almost anything with the Convert class. i.e.
String *sNum = S"100";
int iNum = Convert::ToInt32(sNum);
August 11th, 2003, 05:16 AM
#1 thanks for the answers
#2 new problem:
causes this error:
String* myString = Convert::ToString(comboBox1->Text);
error C2664: 'strlen': Conversion of Parameter 1 from 'System::String __gc *' to 'const char *' not possible