-2

I have a string

May 1988 – June 1992

I want to split this string in such way that I will get two separate strings May 1988 and June 1992 .

I tried the following code:

String sample="May 1988 – June 1992";
String[] arr=sample.split(" - ");
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
user100
  • 69
  • 4
  • 15

2 Answers2

3

The String you are trying to split has a "en dash" (U+2013), while you try to split with a "HYPHEN-MINUS" (U+002D). Seeing the difference with your eyes is pretty hard (dash is slighly longer), but they are different symbols.

just copy and paste the en dash into your split method and it should work:

String[] arr=sample.split(" – ");
OH GOD SPIDERS
  • 3,091
  • 2
  • 13
  • 16
0

The error is yours two dash are not the same : - is not

baddger964
  • 1,199
  • 9
  • 18