hi,

i haven't found any function to convert a string to an integer with this 
string containing signs of an arbitrary number base. won't it be useful?
this is a piece of code i once wrote for this purpose in c:

/*
  * STR:          I string containing symbols
  * AL:           I alphabet to put symbols in order
  * RET:          O result in integer format
  * return value: O number of symbols put into the integer
  */
char stoi_al(char *str, char *al, unsigned int *ret)
{
     int i;
     unsigned int n = 0, base, c = 0;
     char *ind;

     base = strlen(al);
     for (i = 0, str[i]; i++)
     {
         if (!(ind = strchr(al, str[i]))) break;
         n = n * base + ind - al;
         c++;
     }
     *ret = n;
     return c;
}

for i just needed it to work this unsigned integers it does just that 
but can certainly be expanded (using '-' to negate will however imply 
that '-' is not part of AL).
example for hex conversion would be:

stoi("ffffffff", "0123456789abcdef", &i);
printf("%u", i);

is this appreciated or didn't i recognise a function already existing in 
gambas here? i haven't thought about any risks yet when playing around 
with the alphabet...

regards,
tobi

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to