🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #8285

Re: Check for *all* alphanumeric characters...

#8285
From: Torsten Welches
Date: Thu, 05 Apr 2001 14:54
52 lines
2257 bytes
Valentino,

isASCII would be simply:

  public static boolean isASCII(String s) {
    char[] chars = s.toCharArray();
    for (int i = 0; i < chars.length; i++) {
      if (chars[i] > 0xFF) { 
	return false;
      }
    }
    return true;
  }

Torsten

"Valentino Kyriakides" <vkyr@ision.net> wrote:
>Hi,
>
>the following code fragment shows a simple alphanumeric character check
>method, which checks if any char inside a passed string is alphanumeric. -
>Java's "isLetterOrDigit(char)" method's behaviour from the string class
>seems not to include whitespaces, punctuation chars like ".", the "@" sign
>and german umlauts (�������) etc.
>
>Isn't there some equivalent method available which provides something
>similar to "isASCII", which looks for all chars from ...say... the extended
>ASCII charater set or unicode set, so that all above mentioned chars will be
>recognized?
>
>.....
> // check for a string only containing alphanumeric characters
>    private boolean check_alphanumeric (String inputField)
>    {
>     char array[] = inputField.toCharArray();
>     Character chr = new Character(' ');
>     int i = 0;
>
>     while (i < inputField.length()) {
>      if (!chr.isLetterOrDigit (array[i]))
>       return false;
>      i++;
>     }
>     return true;
>    }
>....
>....
>
>Valentino
>
>
Technical Details
Message-ID: <3acc873c$1_1@dnews>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!news.tele.dk!206.252.192.28!news.stealth.net!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!dnews
References: <3acb4854_2@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: f74b3,6f88753f3998c69d
X-Google-Attributes: gidf74b3,public
X-Google-ArrivalTime: 2001-04-05 09:05:07 PST
From: "Torsten Welches" <torsten.welches@who.cares.netcologne.de>
Sender: "Torsten Welches" <torsten.welches@who.cares.netcologne.de>
Reply-To: "Torsten Welches" <torsten.welches@who.cares.netcologne.de>
Subject: Re: Check for *all* alphanumeric characters...
Newsgroups: borland.public.jbuilder.java.language
X-User-Info: 193.158.55.74 193.158.55.74    
References:  <3acb4854_2@dnews> 
NNTP-Posting-Host: 207.105.83.65
Message-ID: <3acc873c$1_1@dnews>
Date: 5 Apr 2001 07:54:52 -0700
X-Trace: dnews 986482492 207.105.83.65 (5 Apr 2001 07:54:52 -0700)
Lines: 53
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!news.tele.dk!206.252.192.28!news.stealth.net!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!dnews