Summary of the Character Segmentation functions absolutely used in javascript, javascript Functions
var data = [['your name', 'myvalue'], ['myr name', 'thivalue']];function string_join(data) { var str = '', arr = []; for (var i = 0; i < data.length; i++) { for (var j = 0; j < data[i].length; j++) { data[i][j] = slash(data[i][j]); } arr.push(data[i].join('/')); } return arr.join(',');}function slash(string) { return String(string).replace(/[\\/,]/g, '\\$&');}function string_split(string) { var c, cur_str = '', cache = [], result = []; for (var i = 0; i < string.length; i++) { c = string.charAt(i); switch(c) { case '\\': cur_str += string.charAt(++i); break; case '/': cache.push(cur_str); cur_str = ''; break; case ',': cache.push(cur_str); cur_str = ''; result.push(cache); cache = []; break; default: cur_str += c; } } if (cur_str.length) { cache.push(cur_str); } if (cache.length) { result.push(cache); } return result;}var before = string_join(data);console.log(before);var after = string_split(before);console.log(after);
Javascript split string
Using the split ('') method, you can use any character to separate the parameters and use spaces to directly pass.
The string is directly separated without any characters.
For example, the character var a = "abcdef"; var B =. split (''); then the output B is 'A', 'B', 'C', 'D', 'E', 'F'
Is the javascript split function that splits strings into arrays?
The split () method is used to split a string into a string array. Syntax stringObject. split (separator, howator) returns a string array. This array is created by dividing the string stringObject into substrings at the boundary specified by separator. The strings in the returned array do not include the separator itself. However, if separator is a regular expression that contains a subexpression, the returned array contains the strings that match the subexpression (but does not include the text that matches the entire regular expression ). Note: If the empty string ("") is used as a separator, each character in the stringObject is separated. Note: The operations executed by String. split () are the opposite to those executed by Array. join. Example:
"2: 3: 4: 5 ". split (":") // Returns ["2", "3", "4", "5"] "| a | B | c ". split ("|") // Returns ["", "a", "B", "c"]