[英]How to do word-wrap based on a specific character?
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 ...,...,....
: 09:30pm - 10.30pm,11.00pm - 12.00pm ...,...,....
我要显示为:
09:30pm - 10.30pm,
11.00pm - 12.00pm,
...,
...,
.
.
.
How to do this? 这个怎么做? Thanks in advance.
提前致谢。
serverResponse.split(",")
这将返回一个字符串数组
根据使用字符串的位置,可以用\\n
或<br>
替换逗号:
YourString.replace(/\,/g,",\n")
You have 2 options: 您有2个选择:
Option 1: 选项1:
var string1 = '09:30pm - 10.30pm,11.00pm - 12.00pm';
string1 = string1.split(',').join(',\n');
Option 2: 选项2:
var string2 = '09:30pm - 10.30pm,11.00pm - 12.00pm';
string2 = string2.replace(/\,/g, ',\n');
The string you describe, with the data separated by commas, is called “comma delimited”. 您描述的字符串(数据用逗号分隔)称为“逗号分隔”。
.CSV
is a common version of this file, short for 'Comma Separated Values.' .CSV
是此文件的通用版本,简称“逗号分隔值”。
You might find this thread to be helpful. 您可能会发现此线程很有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.