0

I try to edit a String input from a TextView via String.split().

The input is a String in Format dd.mm.yyyy and I want to transform it to yyyy-mm-dd I got the input from an intent, set it to the TextView. Later, without changing anything, I read the Text from the TextView and try to split it.

String date = intent.getStringExtra("date");
mDisplayDate.setText(date);
.
.
.
String userDate = mDisplayDate.getText().toString();
Log.i("TAG","userDate = "+ userDate);
String[] separated = userDate.split(".");
Log.i("TAG","Array = "+ Arrays.toString(separated));
newDate = separated[2] + "-" + separated[1] + "-" + separated[0];

Log: userDate = 30.06.2020

Log: Array = [] -> so it is a empty Array... but why?

If I seperate by e.g. a number it works... I am lost...

Felix
  • 284
  • 2
  • 12
  • Make sure the character is really the one you think. It could be any unicode point and you wouldn't know. Otherwise you can always just split by non-digit regex: `[^0-9]` – Nicolas Jun 17 '20 at 12:17
  • 1
    I got the hint that I have to seperate it with "\\." because of the speziall meaning of ".". I searched for a log time, but couldnt find anything. I guess I have to improve my search skills. Thanks @Andreas – Felix Jun 17 '20 at 12:29
  • For me, it is top search result when searching for [`java split period`](https://www.google.com/search?q=java+split+period) using Google. – Andreas Jun 17 '20 at 17:29

0 Answers0