7
I want to share the string in 2 parts (will always be a array divide into two parts - or two elements) each time a vertical bar |
(only in the first case).
For example: I have a string
var string = "João|23anos";
can I give a string.split("|")
and return will be an array ["João", "23 anos"]
. But I’d like to split only in the first case of vertical bar |
and copy the rest of the string to the array;
For example:
var string = "João|||23anos|";
<- In this example it will return this array: ["João", "", "", "23anos", ""]
.
Array I wish I could be printed:
["João", "||23anos|"]
The first vertical bar will only serve to give split
and the rest of the vertical bars should be within the array.
have any tips to learn
regex
? from basic to advanced– Denali
+1, but it is full match, with "TCH" ;-)
– Wtrmute
@Wtrmute Thank you, had written wrong!
– Marconi