Search code examples
androidstringsplitjsonresponse

How to split json response string based on the whitespace between them in android


I have a json response string like this: 2015-09-30 11:09:00 (date and time is a single string) I need to add "at" between "2015-09-30" and "11:09:00". How can I split this date and time so that I can add the word "at" in between them. My requirement::I displayed the date and time in a single textview(without splitting them). But now when I split this, how can I display them on two different text view,i.e; date in first textview and time in second text view.Please help me to sort this problem.


Solution

  • String jsonString = "2015-09-30 11:09:00";
    String dateTime[]=jsonString.split(" ");
    String finalStr = dateTime[1]+" at "+dateTime[0];
    

    i guess this should work

    or String finalStr = jsonString.replace(" "," at ");