0

I am getting a string from server side,which contains words separated by comma. ex:- 09:30pm - 10.30pm,11.00pm - 12.00pm ...,...,.... I want to display it like:

09:30pm - 10.30pm,
11.00pm - 12.00pm,
...,
...,
.
.
.

How to do this? Thanks in advance.

Manoj
  • 289
  • 1
  • 2
  • 11

3 Answers3

1
serverResponse.split(",")

This will return an array of strings

gabriel.santos
  • 160
  • 1
  • 10
1

Depending on where you're using the string, you could replace commas with either \n or <br>:

YourString.replace(/\,/g,",\n")
DarkAjax
  • 15,955
  • 11
  • 53
  • 65
  • 1
    This won't work. Simply doing `.replace(',', '\n')` will replace the first occurence of a comma, but not all. You'll need to use a regular expression like so: `string2.replace(/\,/g, '\n')` – justinledouxweb Apr 08 '16 at 19:24
1

You have 2 options:

Option 1:

var string1 = '09:30pm - 10.30pm,11.00pm - 12.00pm';
string1 = string1.split(',').join(',\n');

Option 2:

var string2 = '09:30pm - 10.30pm,11.00pm - 12.00pm';
string2 = string2.replace(/\,/g, ',\n');
justinledouxweb
  • 1,337
  • 3
  • 13
  • 26