0

I have to split the strings of input text file (which is in hindi language) in java language. Is there is a way to do so ?I have tried to split it into single characters but that doesn't word. For example:

मुझे बहुत सारा काम करना है|  

then output should be

मु  
झे  

ब  
हु  
त

सा  
रा

का  
म

क  
र  
ना

है 
SHEKHAR SHETE
  • 5,964
  • 15
  • 85
  • 143

3 Answers3

0

This will solve your problem

BufferedReader in = null;
        try {
            in = new BufferedReader(new FileReader("your text file path goes here"));
            String read = null;
            while ((read = in.readLine()) != null) {
                String[] splited = read.split("\\s+");
                for (String part : splited) {
                    System.out.println(part);
                }
            }
        } catch (IOException e) {
            System.out.println("There was a problem: " + e);
            e.printStackTrace();
        } finally {
            try {
                in.close();
            } catch (Exception e) {
            }
        }
   }

Note:- provide your full file path to the filereader.

0

All string data types processed in Java are 'Unicode' so you might get unexpected result.

You may refer to this question. I think, it seems similar problem

Community
  • 1
  • 1
Junsuk Park
  • 193
  • 1
  • 13
-1

Try this out

 String s = new String("मुझे बहुत सारा काम करना है");

       for(int i =0 ;i<s.length();i++){
           System.out.println(s.charAt(i));
       }
Ramesh Papaganti
  • 7,311
  • 3
  • 31
  • 36
  • Latin and Devanagari are different. Your code will give output like ` म ु झ े ब ह ु त स ा र ा क ा म क र न ा ह ै | `. But the actual should be like `मु झे ब हु त सा रा का म क र ना है |` . You should use a different algorithm or regex for this. – SibiCoder Sep 08 '16 at 17:28