Acquiring nth character from string or value

Bloodbane

Well-known member
Let's say I have this string : fjiekalmsq and this value : 3044218372

The, say, 4th character from these two is e and 4 but how to acquire 4th character from these with script?
 
hi bb!!

here my functions:

Code:
char getchar(char str, int index) {
    if ( index >= strlength(str) ) index = strlength(str)-1;
    else if ( index < 0 ) index = 0;

    if ( strlength(str) > 0 ) {
        str = strright(str, index);

        if ( strlength(str) > 1 ) {
            index = 1;
            str = strleft(str, index);
        }
    } //else str = "";

    return str;
}


float digit_num(int num) {
    int i = 0;
    int tmp_num = num;

    if ( num == NULL() ) return 0;
    if ( tmp_num <= 0 ) {
        ++i;
    } else {
        while( tmp_num > 0 ) {
            int digit;

            digit = trunc(tmp_num%10); // ex. 526%100 = 26
            tmp_num = trunc(tmp_num/10); // ex. 526/100 = 5
            ++i;
        } // fine while
    }

    return i;
}

int trunc(int num) {
    int sign = 1;

    if ( num < 0 ) {
        sign = -1;
        num *= -1;
    }

    num = num%(num+1);
    num *= sign;

    return num;
}

use getchar(str,index) for strings and digit_num(index) for nums  ;)
 
Back
Top Bottom