zizi21
asked on
isalnum
Hi,
Could anyone tell me the difference between isalnum and a-z ||A-Z||0-9 ?
Thanks!
Zizi
Could anyone tell me the difference between isalnum and a-z ||A-Z||0-9 ?
Thanks!
Zizi
Are you refereing to a regular expression?
ASKER
Hi Anthony,
It is just that I thought of using the isalnum which I thought is a function that checks for alphabets and numeric values only..
Is is correct to assume that alphabets are A-Z, a-z and numbers is 0-9. The reason i ask is, lets say , I have another language installer on my machine. An 'A' in my language would be displayed differently, does isalnum still consider it as 'A'.
When it is says alphabets, does it means English ascii values...
Thanks
It is just that I thought of using the isalnum which I thought is a function that checks for alphabets and numeric values only..
Is is correct to assume that alphabets are A-Z, a-z and numbers is 0-9. The reason i ask is, lets say , I have another language installer on my machine. An 'A' in my language would be displayed differently, does isalnum still consider it as 'A'.
When it is says alphabets, does it means English ascii values...
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi infinity,
What do you mean by locale...It is just that currently isalnum is giving me true for empty space as well..that's why i am very confuse..
What do you mean by locale...It is just that currently isalnum is giving me true for empty space as well..that's why i am very confuse..
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Can you use a debugger to look at the value or print out the value using something like:
printf("0x%x", c); // where c contains the value that you are passing to isalnum
printf("0x%x", c); // where c contains the value that you are passing to isalnum
ASKER
Got it..I was adding the nul character...
by the way, which would u recommend, using A , a way or isalnum way ? thanks
by the way, which would u recommend, using A , a way or isalnum way ? thanks
>> which would u recommend, using A , a way or isalnum way ?
isalnum is a very easy way to determine whether a character is an alphanumeric character or not ... so it's usually the recommended way.
However, you didn't explain what you plan to do with this, so maybe your situation requires a different approach. Can you explain what you are trying to do ?
isalnum is a very easy way to determine whether a character is an alphanumeric character or not ... so it's usually the recommended way.
However, you didn't explain what you plan to do with this, so maybe your situation requires a different approach. Can you explain what you are trying to do ?
ASKER
I am actually a beginner..My teacher taught the functions in class, only definitions were given. So, i thought, maybe I could learn more if I try doing it.. isspace, isalnum, isalpha, isdigit
and the definition said isalnum is for alphanumeric characters but my friend told me that , if you use different language, you are not necesary going to get alphanumeric characters..So, it is better to use A || a way...I did few simple programs to test these out.
I guess, my friend was wrong.
What i am trying to do is to test whether the word is alphanumeric. Thank you very much...
and the definition said isalnum is for alphanumeric characters but my friend told me that , if you use different language, you are not necesary going to get alphanumeric characters..So, it is better to use A || a way...I did few simple programs to test these out.
I guess, my friend was wrong.
What i am trying to do is to test whether the word is alphanumeric. Thank you very much...
ASKER
I read the link above.
Sorry, if i am repeating this alphanumeric means any English alphabets A-Z or a-z or 0-9. Any others does not fall in alphanumeric.
Thanks
Sorry, if i am repeating this alphanumeric means any English alphabets A-Z or a-z or 0-9. Any others does not fall in alphanumeric.
Thanks
>> So, i thought, maybe I could learn more if I try doing it..
That's a very good idea :)
Take a look at the URL I posted ... It points to a reference for the isalnum and other similar functions. You'll find a lot more information, including example code there.
>> but my friend told me that , if you use different language, you are not necesary going to get alphanumeric characters
If your locale is properly set for that different language, then isalnum should handle that fine.
>> So, it is better to use A || a way...
The default locale is already using the normal A-Za-z alphabet. So, unless your system has a different locale configured, and you want to be able to check for A-Za-z, just go with isalnum.
>> What i am trying to do is to test whether the word is alphanumeric.
Then you just need to call isalnum for every letter in the word. If you want, you can show us your code, and we can take a look at it to see if it's ok.
That's a very good idea :)
Take a look at the URL I posted ... It points to a reference for the isalnum and other similar functions. You'll find a lot more information, including example code there.
>> but my friend told me that , if you use different language, you are not necesary going to get alphanumeric characters
If your locale is properly set for that different language, then isalnum should handle that fine.
>> So, it is better to use A || a way...
The default locale is already using the normal A-Za-z alphabet. So, unless your system has a different locale configured, and you want to be able to check for A-Za-z, just go with isalnum.
>> What i am trying to do is to test whether the word is alphanumeric.
Then you just need to call isalnum for every letter in the word. If you want, you can show us your code, and we can take a look at it to see if it's ok.
>> Sorry, if i am repeating this alphanumeric means any English alphabets A-Z or a-z or 0-9. Any others does not fall in alphanumeric.
As I said, it depends on the locale. The default locale will indeed use the default A-Za-z alphabet, but when a different locale is set, different characters can be identified as alphanumeric.
A quote from the site I linked to :
"Notice that what is considered a letter may depend on the locale being
used; In the default C locale, what constitutes a letter is what returns
true by either isupper or islower."
and for isupper :
"Notice that what is considered a letter may depend on the locale being
used; In the default C locale, an uppercase letter is any of: A B C D E F
G H I J K L M N O P Q R S T U V W X Y Z."
(similar for islower).
As you see, they explicitly say that it depends on the locale.
In any case, you shouldn't have to worry about this since you're only learning. Just go with isalnum, and you should be fine.
As I said, it depends on the locale. The default locale will indeed use the default A-Za-z alphabet, but when a different locale is set, different characters can be identified as alphanumeric.
A quote from the site I linked to :
"Notice that what is considered a letter may depend on the locale being
used; In the default C locale, what constitutes a letter is what returns
true by either isupper or islower."
and for isupper :
"Notice that what is considered a letter may depend on the locale being
used; In the default C locale, an uppercase letter is any of: A B C D E F
G H I J K L M N O P Q R S T U V W X Y Z."
(similar for islower).
As you see, they explicitly say that it depends on the locale.
In any case, you shouldn't have to worry about this since you're only learning. Just go with isalnum, and you should be fine.
ASKER
I am sorry if i am asking too much questions. I am very curious too know this,,,i checked at the control panel and i went to regional, how do i find whether the C locale is used.
What country are you in ? And what language is your operating system set to ?
>> how do i find whether the C locale is used.
You can use this piece of code :
#include <stdio.h>
#include <locale.h>
int main(void) {
fprintf(stdout, "current locale : %s\n", setlocale(LC_ALL, 0));
return 0;
}
See this reference page for more info :
http://www.cplusplus.com/reference/clibrary/clocale/setlocale.html
>> how do i find whether the C locale is used.
You can use this piece of code :
#include <stdio.h>
#include <locale.h>
int main(void) {
fprintf(stdout, "current locale : %s\n", setlocale(LC_ALL, 0));
return 0;
}
See this reference page for more info :
http://www.cplusplus.com/reference/clibrary/clocale/setlocale.html
ASKER
Hi,
I am in Singapore. Some use Windows but mostly unix is used.
thank you very much. I would read more on it...
I am in Singapore. Some use Windows but mostly unix is used.
thank you very much. I would read more on it...
ASKER
i just checked it with the code above and it is C. thank you
What do you mean the difference? I believe that isalnum will return true if the value passed is in the range you listed.