Summary of the Character Segmentation functions absolutely used in javascript, javascript Functions

Source: Internet
Author: User

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"]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.