-5

hi have some text like this :

What would you like to eat?

شما چي ميل  داريد؟

I’d like a bowl of tomato soup, please.

لطفا يک کاسه سوپ گوجه فرنگي برام بياريد

The waiter seems to be in a hurry to take our order.

گارسن بنظر مياد خيلي عجله داره که سفارش ما رو بياره

i want to Detect and put english Sentence in one array and Persian Sentence in another array

How can i do ؟

alis
  • 5
  • 4

1 Answers1

0

Assuming all your text is in a file and that English and persian translations are on different lines. What you need to do is read each line from the file and check if it is ASCII or not.

How do you check that?

import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;

public class StringUtils {

  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);
  }

  public static void main (String args[])
    throws Exception {

     String test = " برام ";
     System.out.println(test + " isPureAscii() : " + StringUtils.isPureAscii(test));
     test = "Real";
     System.out.println(test + " isPureAscii() : " + StringUtils.isPureAscii(test));

     /*
      * output :
      *    برام isPureAscii() : false
      *   Real isPureAscii() : true
      */
  }
}
Nishit
  • 1,276
  • 2
  • 11
  • 25