Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Couple of Questions
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#4
RE: Couple of Questions

Just for future reference, to you initial request for #2.

Integer to string conversion is easy, just append the integer onto the end of a string and angelscript will do the rest.
//Example usage

void example() {
int x = 50;
string s = "" + x;
}
String to UNSIGNED integer conversion, not so easy, need to build a parsing function. I've already built one though, so feel free to use it.
//Usage:
void example() {
string s = "a1b2c3d4";
int x = parseStringInt(s);
//X now equals 1234
}
//Helper functions written by me (Apjjm):
int getDigit(uint8 digit) {
    int d = digit-48; //48 is ASCII code for 0
    return ((d >= 0)&&(d<=9)) ? d : -1;
}
int parseStringInt(string str) {
    int output = 0;
    for(uint i=0; i<str.length(); i++)
     {
      int digit = getDigit(str[i]);
      output = (digit > -1)?(10*output+digit):(output);
     }
    return output;
}
(This post was last modified: 07-07-2011, 01:25 AM by Apjjm.)
07-07-2011, 01:22 AM
Find


Messages In This Thread
Couple of Questions - by DRedshot - 07-06-2011, 11:53 PM
RE: Couple of Questions - by MrBigzy - 07-07-2011, 12:20 AM
RE: Couple of Questions - by DRedshot - 07-07-2011, 12:26 AM
RE: Couple of Questions - by Apjjm - 07-07-2011, 01:22 AM
RE: Couple of Questions - by DRedshot - 07-07-2011, 01:26 AM



Users browsing this thread: 1 Guest(s)