Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
August 10th, 2003, 12:35 PM
 SirX
Contributing User

Join Date: Aug 2003
Posts: 64
Time spent in forums: 24 m 30 sec
Reputation Power: 11
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

How can I convert Label1->Text to Integer or the length of Label1->Text?

#2
August 10th, 2003, 02:13 PM
 movEAX_444
Cast down

Join Date: Jul 2003
Location: Sweden
Posts: 321
Time spent in forums: 5 h 56 m 35 sec
Reputation Power: 11
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/d...wTextLength.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
August 10th, 2003, 02:20 PM
 ygdrasyl
Contributing User

Join Date: Feb 2002
Location: BCN
Posts: 84
Time spent in forums: 1 h 1 m 4 sec
Reputation Power: 12
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
August 10th, 2003, 04:47 PM
 Nem
Contributing User

Join Date: Jun 2003
Posts: 109
Time spent in forums: < 1 sec
Reputation Power: 11
In C++ .NET you can convert almost anything with the Convert class. i.e.

String *sNum = S"100";
int iNum = Convert::ToInt32(sNum);

#5
August 11th, 2003, 06:16 AM
 SirX
Contributing User

Join Date: Aug 2003
Posts: 64
Time spent in forums: 24 m 30 sec
Reputation Power: 11

#2 new problem:

Code:
```String* myString = Convert::ToString(comboBox1->Text);
int i=strlen(myString);```

causes this error:
error C2664: 'strlen': Conversion of Parameter 1 from 'System::String __gc *' to 'const char *' not possible

 Viewing: Dev Shed Forums > Programming Languages > C Programming > How can I get Label1->Text To Integer or the length of Label1->Text