var string="content=ABCDEFGHIJKLMN=" var ca = string.split("="); ca[0]=content; ca[1]=ABCDEFGHIJKLMN; ca[2]=""; But I don't want to intercept the second equal sign (it needs to be retained), how should I deal with this?
You are not suitable for programming, kid. . . Just getca[1]+"=". Why do you have to get the original equal sign? The idea must be flexible. The wordequivalentis very important for a programmer.
After reading your comments in each answer, I would guess that your intention is to try to find a method built into the programming language to implement this function. You only need to call it, such as calling a function or adding parameters.
Right?
But the problem is that the current language may not have such a built-in feature (because I am not very proficient in js myself, so I dare not make a conclusion), so you need to implement it yourself.
In fact, the functions built into the language are just pre-implemented by others. You insist on finding one, but you fall into a trap.
As @G_Koala_C saidSolving problems in a simple and intuitive way is the way to go.
If there are more than two = wouldn’t it be a trap? So I have to
str1 = ca[0]; ca.shift(); str2 = ca.join('=');
Personally, I like regular expressions, but you can also use indexof to find the first =. But this method also needs to determine whether the return value is -1.
separatorrequired. A string or regular expression to split the stringObject from where specified by this parameter. howmanyOptional. This parameter specifies the maximum length of the returned array. If this parameter is set, no more substrings will be returned than the array specified by this parameter. If this parameter is not set, the entire string will be split regardless of its length.
666
Use regular expressions
You are not suitable for programming, kid. . .
Just get
ca[1]+"="
. Why do you have to get the original equal sign? The idea must be flexible. The wordequivalentis very important for a programmer.After reading your comments in each answer, I would guess that your intention is to try to find a method built into the programming language to implement this function. You only need to call it, such as calling a function or adding parameters.
Right?
But the problem is that the current language may not have such a built-in feature (because I am not very proficient in js myself, so I dare not make a conclusion), so you need to implement it yourself.
In fact, the functions built into the language are just pre-implemented by others. You insist on finding one, but you fall into a trap.
As @G_Koala_C said
Solving problems in a simple and intuitive way is the way to go.
If there are more than two = wouldn’t it be a trap? So I have to
Personally, I like regular expressions, but you can also use indexof to find the first =. But this method also needs to determine whether the return value is -1.
separatorrequired. A string or regular expression to split the stringObject from where specified by this parameter.
howmanyOptional. This parameter specifies the maximum length of the returned array. If this parameter is set, no more substrings will be returned than the array specified by this parameter. If this parameter is not set, the entire string will be split regardless of its length.
Usage source http://www.w3school.com.cn/js...
I looked at the source code of the
querystring
module ofnode.js
. According to the source code, it is processed like this: