I have string in jQuery.
var s = "Text1, Text2, Text,true";
I need split this variable in two part:
var s1 = substring(...); //after this s1="Text1, Text2, Text"
var s2 = substring(...); //after this s2="true"
Can you help me split variable?
For example, comma(,). Python provides a method that split the string from rear end of the string. The inbuilt Python function rsplit() that split the string on the last occurrence of the delimiter. In rsplit() function 1 is passed with the argument so it breaks the string only taking one delimiter from last.
Split is used to break a delimited string into substrings. You can use either a character array or a string array to specify zero or more delimiting characters or strings. If no delimiting characters are specified, the string is split at white-space characters.
The splitting of comma separated values in an R vector can be done by unlisting the elements of the vector then using strsplit function for splitting. For example, if we have a vector say x that contains comma separated values then the splitting of those values will be done by using the command unlist(strsplit(x,",")).
var s="Text1, Text2, Text,true";
var lastIndex = s.lastIndexOf(",")
var s1 = s.substring(0, lastIndex); //after this s1="Text1, Text2, Text"
var s2 = s.substring(lastIndex + 1); //after this s2="true"
s1 = s.split(',');
s2 = s1.pop();
s1 = s1.join(',');
(untestet)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With