### Thread: How can I get Label1->Text To Integer or the length of Label1->Text

1. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Aug 2003
Posts
64
Rep Power
15

#### How can I get Label1->Text To Integer or the length of Label1->Text

How can I convert Label1->Text to Integer or the length of Label1->Text?
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.

http://msdn.microsoft.com/library/de...TextLength.asp

Code:
```int s2n(char *str)
{
//accept a string, and return the number ("1016" will be 1016.. works for negative)
int n=0;
int len=slen(str);
int base=1;
int neg=(str[0]=='-')?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 0;
return neg ? n * -1 : n; //if negative, times by -1
}```
3. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Feb 2002
Location
BCN
Posts
84
Rep Power
17
If what you want is the value represented by the string you could use the atoi : (C)
#include <stdlib.h>
int atoi(const char *s).
4. No Profile Picture
Nem
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2003
Posts
109
Rep Power
16
In C++ .NET you can convert almost anything with the Convert class. i.e.

String *sNum = S"100";
int iNum = Convert::ToInt32(sNum);
5. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Aug 2003
Posts
64
Rep Power
15
```String* myString = Convert::ToString(comboBox1->Text);