[英]How to split string into multiple strings along certain characters in Javascript
I am new at programming so it would be help if the answers very simple, but in Javascript I have a variable called "time". 我是编程新手,所以如果答案很简单,这将对您有所帮助,但是在Javascript中,我有一个名为“ time”的变量。 It might be "10:36 PM" for example, and I want to split it along the colon and the space, so that it becomes the three different variables: 10, 36, and PM
例如,它可能是“ 10:36 PM”,我想将其沿结肠和空间分开,以使其成为三个不同的变量:10、36和PM
I know how to cut off the end or beginning of variables, but I need something that will save all of the parts as a separate variable. 我知道如何截断变量的结尾或开头,但是我需要将所有部分另存为单独变量的东西。
You can do. 你可以做。
time = time.split(/:|\s/);
Let me explain what's going on inside the split call. 让我解释一下拆分调用中发生的情况。
The /
at the start and the end means it's a regular expression. 在
/
在开始和结束意味着它是一个正则表达式。 The :
is just a colon, \\s
means a space character, the |
:
只是一个冒号, \\s
表示一个空格字符, |
表示空格|
between them is special in regular expressions and basically means or
. 它们之间的区别是正则表达式的特殊之处,基本上是指
or
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.