Re: validates characters

From: John Harrison (john_andronicus_at_hotmail.com)
Date: 07/28/04


Date: Wed, 28 Jul 2004 12:46:22 +0100


"Lyle Ladeira" <ladeiras@mweb.co.za> wrote in message
news:ce826t$kqp$1@ctb-nnrp2.saix.net...
> hey
>
> the only thing that should be valid is letters and spaces
> A-Z a-z and spaces, tabes etc...
>
> thanx
>

OK, the way to do this is to loop through all the characters of the string
testing each one. As soon as you find an invalid character then you know
that the whole string is invalid. If you don't find an invalid character
then the string is valid. Something like this

#include <ctype.h>

bool is_valid(const char* str)
{
    while (*str)
    {
        if (!isalpha(*str) && !isspace(*str)) // if not alphabetic and not a
space ...
            return false; // .. then its not valid
        ++str;
    }
    return true; // all chars tested ok so its valid
}

john



Relevant Pages

  • FASTEST way to try all strings (a until ZZZZZZZZZZZZZZZZZZZZZZZZ)
    ... I need to find the FASTEST way to get a string in a Loop, ... and used the parameters with the info on a stupid way. ... Try avery combination of letters... ...
    (microsoft.public.dotnet.languages.vb)
  • FASTEST way to try all strings (a until ZZZZZZZZZZZZZZZZZZZZZZZZ)
    ... I need to find the FASTEST way to get a string in a Loop, ... and used the parameters with the info on a stupid way. ... Try avery combination of letters... ...
    (microsoft.public.dotnet.general)
  • Re: Help, its my first ASM homework
    ... > letters in the string you input. ... The main problem is that you are using LOOP to count off the ...
    (comp.lang.asm.x86)
  • Re: Stripping letters from filename
    ... I need to do a loop that starts stripping the letters from the front of this file name until it reaches the "Cat" part. ... one more thing you might be able to help with: I've got a string of text in a label. ...
    (microsoft.public.dotnet.languages.vb)
  • extension_pack
    ... It is used to set upper loop -- limits for non-deterministic values thus avoiding the use of access -- types and enabling the functions to be used for synthesizeable code. ... DivisorVal: integer) return std_logic_vector; function "/"(DividendVal: string; DivisorVal: integer) return std_logic_vector; ... for loopVar in 0 to slvVal'length/4-1 loop ... end loop; if then return not resultVar; -- "width mismatch" errors here are due to improper sizing of the vector that this function is assigned to else return resultVar; -- "width mismatch" errors here are due to improper sizing of the vector that this function is assigned to end if; ...
    (comp.lang.vhdl)