Sunday, May 20, 2012

Create Ascii Checker tools with Java Swing

Question : Need ascii check before paste word into CMS Template
Answer : Need fast checker rather than re-type offer one by one.

Create swing project with Netbeans for that purpose.

What important thing is you must decide what ascii encoder you need to use in your checking. my one only use this



static CharsetEncoder asciiEncoder = Charset.forName("US-ASCII").newEncoder(); // or "ISO-8859-1" for ISO Latin 1

  public static boolean isPureAscii(String v) {  
      return asciiEncoder.canEncode(v);
  }


and this is what I build for Ascii Checker

and code for Check button was


private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        int koral =0;
        
        for (int j = jTextArea1.getText().length(); j>= koral; j--) {
            String s = jTextArea1.getText().substring(j);//substring(koral, j);            
            if (isPureAscii(s) == false ) {
                jLabel1.setText("isPureAscii() --> "+isPureAscii(jTextArea1.getText())+"  Failed at position : "+ j);
                //System.out.println("Char at position: "+ j);                            
                break;
            }else
                jLabel1.setText("isPureAscii() --> " +isPureAscii(jTextArea1.getText()));
        }
    }           

the next step go to my Github page for more details

2 comments:

Ohotnikof said...

Thank you. I was looking for.

Unknown said...

You are most welcome