0

I want to split a Hindi paragraph into sentences. Each sentence is separated by '|' . I tried the following code :

String[] translated_values=text.split("|");

Sample text :

मनोवैज्ञानिक परीक्षण। खुफिया भागफल खुफिया की उम्र से संबंधित उपाय के लिए (बुद्धि) टेस्ट। चिकित्सा देखभाल

but it doesn't work. This works when splitting with other symbols like , etc . please help me.

Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
julika Zen
  • 357
  • 6
  • 22

3 Answers3

2

| is a special char in regex (alternation operator) which will do the regex logical OR operation. You need to escape | in-order to match a literal pipe symbol.

String[] values = text.split("\\|");
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
2

You need to escape it:

Try:

String[] translated_values=text.split("\\|"); 
Akash Rajbanshi
  • 1,553
  • 11
  • 23
1

Instead of using the character | directly, use the unicode value of it. This should work

String[] translated_values=text.split("\u0964");
Vojtech Ruzicka
  • 16,384
  • 15
  • 63
  • 66