Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2010
    Posts
    59
    Rep Power
    0

    Default Non-ASCII Characters

    Hello. I have made a text analyser program which counts the different characters. One feature is that it needs to count the number of printing characters (as opposed to non-printing such as spaces, tabs and line returns).

    I am testing my program, but have just realised that the program does not recognise non-ascii characters such as and (British pound sterling sign).
    I used this routine to process a string of text to count the number of printable characters:

    for (int z=0; z<testString.length() ;z++)
    {
    charray[z]=testString.charAt(z);
    if ((int)charray[z]>32 && (int)charray[z]<=126)
    // Please note ascii codes for printing characters are from 32 to 126 (32 is space).
    {
    numberofprintables=numberofprintables+1;
    }
    }

    I have one idea to get around the problem which is to test if the character is a non-printable character (i.e. <32 in the ascii codes). Hence if it is not then the character must be a printing character.

    Would this resolve the issue or are there non-ascii characters that are non-printable i.e. forms of spaces?

    Many thanks!

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    10

    Default

    See the API docs for the Character class.

  3. #3
    Join Date
    Apr 2010
    Posts
    59
    Rep Power
    0

    Default

    I have had a read of the API for Characters. I realise that I should be looking for Unicode characters! My existing code counts the number of printable characters (in a String called testString) by doing:

    for (int z=0; z<testString.length() ;z++)
    {
    charray[z]=testString.charAt(z);

    if ((int)charray[z]>32 && (int)charray[z]<=126)
    {
    numberofprintables=numberofprintables+1;
    }
    }

    Can someone please tell me how I could change this into Unicode? Is there a way?

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    10

    Default

    If you read the Character class than why are you using int vals?

    Use the Character class.
    Last edited by masijade; 05-06-2010 at 09:05 PM.

  5. #5
    Join Date
    Apr 2010
    Posts
    59
    Rep Power
    0

    Default

    Sorry masijade I don't understand:

    If you read the Character class than why are you using int vals?
    Use the Character class.

    How can you use the Character class?

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,038
    Blog Entries
    7
    Rep Power
    23

    Default

    Quote Originally Posted by AJArmstron@aol.com View Post
    How can you use the Character class?
    It has a whole bunch of static methods you can use ...

    kind regards,

    Jos

  7. #7
    Join Date
    Apr 2010
    Posts
    59
    Rep Power
    0

Similar Threads

  1. ASCII Triangle
    By physics in forum New To Java
    Replies: 2
    Last Post: 03-13-2010, 02:00 AM
  2. Randomly generate a range of Ascii Characters
    By Jamison5213 in forum New To Java
    Replies: 2
    Last Post: 12-20-2009, 03:48 AM
  3. [SOLVED] special characters (ASCII)
    By AlejandroPe in forum New To Java
    Replies: 8
    Last Post: 04-06-2009, 10:42 AM
  4. I need help with ascii characters
    By Grandon in forum Eclipse
    Replies: 17
    Last Post: 11-08-2008, 03:12 AM
  5. Printing ASCII values of characters
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-21-2008, 05:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •