• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4584
  • Last Modified:

java function to test string for double byte characters

Hi,
   I need to know if there is a way in java to check if the input string contains double byte characters.
Thanks
0
res_this
Asked:
res_this
  • 3
1 Solution
 
marklorenzCommented:
Try this:

"java to convert the string text(with double byte code character) I receive from JTextField and
convert it to ASCII code"

http://java.ittoolbox.com/groups/technical-functional/java-l/how-to-add-double-byte-characterexample-chinese-characterto-mysql-database-using-java-484864


0
 
CEHJCommented:
*All* Java characters are double byte, in the sense that a String is composed of char[] and char is two bytes
0
 
res_thisAuthor Commented:
I dont need to convert, just need to check if the double byte characters exist in the string
0
 
CEHJCommented:
How many bytes are used depends on the encoding. For UTF-8, you could test as follows:
        for(int i = 0;i < s.length();i++) {
            String test = "" + s.charAt(i);
            byte[] bytes = test.getBytes("UTF-8");
            if (bytes.length > 1) {
                System.out.printf("char %s is %d bytes long\n", test, bytes.length);
            }
        }

Open in new window

0
 
CEHJCommented:
:-)
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now