Hey!
If you store text into the string, you can check it's length (
str_len). As for 'numbers only' maybe
str_stri can help, just a quick thought.
Greets!
Edit: I think str_stri was a bad idea, not going to work...probably str_cmpi is a better for this case.
Edit2: I've spent a little time and came up with this (since I don't know how to handle regex with lite-c and it might not even support it):
#include <acknex.h>
#include <default.c>
#define PRAGMA_POINTER
STRING *non_numeric_str = "0123456789a";
STRING *numeric_str = "5325";
STRING *empty_str = "";
// receives a STRING and position (num) of a character in that STRING
// returns a single character as a STRING
STRING *get_next_char(STRING *src_str, int num)
{
if(!src_str)
{
return NULL;
}
if(num > str_len(src_str))
{
return NULL;
}
STRING *temp_str = "";
str_cpy(temp_str, src_str);
str_trunc(temp_str, str_len(src_str) - num);
str_clip(temp_str, num - 1);
return temp_str;
}
// returns TRUE (1) if string is numeric
// otherwise returs FALSE (0)
var is_numeric_str(STRING *src_str)
{
if(!src_str)
{
return false;
}
int i = 0, j = 0, res = true;
for (i = 0; i < str_len(src_str); i++)
{
STRING *temp_str = get_next_char(src_str, i + 1);
for (j = 0; j < 10; j++)
{
if (!str_cmpi(temp_str, str_for_num(NULL, j)))
{
res = false;
continue;
}
res = true;
break;
}
if(res == false)
{
break;
}
}
return res;
}
// returns TRUE (1) is string's length is zero
// otherwise returns FALSE (0)
var is_empty_str(STRING *str)
{
if(!str)
{
return false;
}
if(str_len(str) > 0)
{
return false;
}
else
{
return true;
}
}
// main game function
void main()
{
var numeric1 = is_numeric_str(non_numeric_str);
var numeric2 = is_numeric_str(numeric_str);
var empty = is_empty_str(empty_str);
while(!key_esc)
{
DEBUG_VAR(numeric1, 0);
DEBUG_VAR(numeric2, 20);
DEBUG_VAR(empty, 40);
wait(1);
}
}
Edit3: my code above probably is not the best and easiest ways... I just wanted to give it a try. hopefully some other users may point out a better solution.