703 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

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...