Hi - I want to query a text string and see if the result is either..
Upper case
Lower case
Numeric
Is this possible? (irrelevent of the content, I just want to know case or numeric)
Otherwise I've got to query the string value and "say" if it's any one character of "DURLBF" or "123456" or "durlbf" then do something.
[NXC] Can I querey a string to determine it's case?
Re: [NXC] Can I querey a string to determine it's case?
Code: Select all
enum szcase
{ none = 0, upper, lower, both, num };
int n;
string sz = "this is a string";
szcase sc = none;
if(sscanf(sz, "%d", n) == EOF)
{
for(unsigned int i = 0; i < strlen(sz); ++i)
{
if(sz[i] >= 'A' && sz[i] <= 'Z')
sc |= upper;
if(sz[i] >= 'a' && sz[i] <= 'z')
sc |= lower;
}
}
else
{
sc = num;
NumOut(0, 0, num, 0);
}
sscanf()
...Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE
Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
Re: [NXC] Can I querey a string to determine it's case?
Wonderful! Many thanks. I'll have a play.
Even if scanf isn't supported I didn't realise you could "do" <>A-Z <>a-z etc,
... in fact, my string will only ever contain one character/numeral, so I can just use. coolio!
{
if(sz >= 'A' && sz <= 'Z')
sc |= upper;
if(sz >= 'a' && sz <= 'z')
sc |= lower;
}
}
else
{
sc = num;
Even if scanf isn't supported I didn't realise you could "do" <>A-Z <>a-z etc,
... in fact, my string will only ever contain one character/numeral, so I can just use. coolio!
{
if(sz >= 'A' && sz <= 'Z')
sc |= upper;
if(sz >= 'a' && sz <= 'z')
sc |= lower;
}
}
else
{
sc = num;
Re: [NXC] Can I querey a string to determine it's case?
Read the character one time from the string like this:
Then, if you want, you can use the standard library ctype routines for checking characters.
http://bricxcc.sourceforge.net/nbc/nxcd ... ample.html
e.g., isupper, islower, isdigit
You don't need the OR-equal stuff (|=) since you are only looking at a single character.
John Hansen
Code: Select all
char ch = sz[0]; // the one and only character in the string
http://bricxcc.sourceforge.net/nbc/nxcd ... ample.html
e.g., isupper, islower, isdigit
You don't need the OR-equal stuff (|=) since you are only looking at a single character.
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
Re: [NXC] Can I querey a string to determine it's case?
Oh, right, forgot about those nifty little
is_()
s.
Code: Select all
char ch = sz[0];
if(isdigit(ch)) {
}
else if(isupper(ch)) {
}
else if(islower(ch)) {
}
else {
}
Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE
Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
Who is online
Users browsing this forum: Semrush [Bot] and 0 guests