Raised This Month: $32 Target: $400
 8% 

How to detect numbers and letters in an string?


Post New Thread Reply   
 
Thread Tools Display Modes
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-01-2009 , 12:55   Re: How to detect numbers and letters in an string?
Reply With Quote #11

Quote:
Originally Posted by Bugsy View Post
My mistake

You left out a closing brace for the for-loop in both CountNumbers functions
Where?


Quote:
so what sould i do?T_T
Try :

Code:
IsContainingLetters( const String[] ) {     new Count;     new Len = strlen( String );         for ( new i = 0 ; i < Len ; i++ )     {         if ( isalpha( String[ i ] ) )  { return true; }     }         return false; }
__________________

Last edited by Arkshine; 07-01-2009 at 14:05.
Arkshine is offline
_lol_
Senior Member
Join Date: Apr 2009
Old 07-01-2009 , 13:09   Re: How to detect numbers and letters in an string?
Reply With Quote #12

thanks
__________________
_lol_ is offline
loiraolhosazul
Member
Join Date: May 2020
Old 08-23-2021 , 18:32   Re: How to detect numbers and letters in an string?
Reply With Quote #13

how would it be to accept only letters and numbers? both uppercase and lowercase letters
loiraolhosazul is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-23-2021 , 19:13   Re: How to detect numbers and letters in an string?
Reply With Quote #14

Use a loop to check each character in the string.

Check that the char is between 0-1, a-z, A-Z. Many ways to do this.

PHP Code:
bool:IsStringLettersAndOrNumbers( const szString[] )
{
    new 
bool:bStringOk true iLen strlenszString );
    
    for ( new 
iLen i++ )
    {
        if ( !( 
'0' <= szString] <= '9' ) && !( 'a' <= szString] <= 'z' ) && !( 'A' <= szString] <= 'Z' ) )
        { 
             
bStringOk false;
             break;
        } 
    }
    
    return 
bStringOk;

__________________

Last edited by Bugsy; 08-23-2021 at 20:51.
Bugsy is offline
loiraolhosazul
Member
Join Date: May 2020
Old 08-24-2021 , 10:55   Re: How to detect numbers and letters in an string?
Reply With Quote #15

Quote:
Originally Posted by Bugsy View Post
Use a loop to check each character in the string.

Check that the char is between 0-1, a-z, A-Z. Many ways to do this.

PHP Code:
bool:IsStringLettersAndOrNumbers( const szString[] )
{
    new 
bool:bStringOk true iLen strlenszString );
    
    for ( new 
iLen i++ )
    {
        if ( !( 
'0' <= szString] <= '9' ) && !( 'a' <= szString] <= 'z' ) && !( 'A' <= szString] <= 'Z' ) )
        { 
             
bStringOk false;
             break;
        } 
    }
    
    return 
bStringOk;

thanks
loiraolhosazul is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 21:14.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode