1.1k views
in Embedded Wizard Studio by
Hi,

I have text view wich i edit with my virtual keyboard using only numbers. Then i need to convert it to int, but i can not find how. I tried int32(string) operator similar to string(something), but it didn't work.

1 Answer

0 votes
by

Hi, 

If you really want to cast a string into an int, you need to create an own method that runs through each character of a string.

For example method StringToInt32( string aString ) that returns a int32:

var int32 result = 0;

var int32 i = 0;
var char s = aString[i];

while ( s >= '0' && s <= '9' )
{
  result = 10 * result + ( s - '0' );
  i = i + 1;
  s = aString[i];
}

return result;


Just an idea: Instead of using a string input (your text view), I would suggest to create an own input that only allows integer values. You could use the standard "Text Editor" (see Components in Gallery), change its String-property to int32 (modify its onSet and onGet) and modify also the slots like onCharacterKey, which should only accept int-values. Alternative: Use the String-property, but remember any changes to int in another int-property that is accessible. I guess this would be a cleaner way to avoid string casting. It is up to you.

HTH,
Chris

Ask Embedded Wizard - Archive

Welcome to the Ask Embedded Wizard archive. This community forum served us well for many years, but we've evolved our support approach!

Your resources:

The Embedded Wizard Online Documentation provides comprehensive documentation, tutorials, examples and ready-to-use software packages.

For dedicated assistance, explore our Embedded Wizard Product Support.

You can still browse the valuable discussions from our community history here.

Embedded Wizard Website | Privacy Policy | Imprint

...