split Summary Divides the string into substrings, optionally separated by a delimiter. Signatures Click on a signature to select it and view its documentation. public string[] split() public string[] split(string delimiter) public string[] split(string delimiter, int limit) public string[] split(System.RegExp delimiter) public string[] split(System.RegExp delimiter, int limit) Usage public string[] split() public string[] split(string delimiter) public string[] split(string delimiter, int limit) public string[] split(System.RegExp delimiter) public string[] split(System.RegExp delimiter, int limit) Returns The original string stored in an array of size 1. An array of substrings between the delimiter(s). An array of substrings between the delimiter(s), limited to the provided limit argument. An array of substrings and matches. An array of substrings and matches, limited to the provided limit argument. Parameters delimiter The boundary string. Parameters delimiter The boundary string. limit The size to limit the resulting array to. Parameters delimiter The boundary as a regular expression. Parameters delimiter The boundary as a regular expression. limit The size to limit the resulting array to. Description When split is called with no arguments, an array of size 1 is created, with the array's only element being the original string. Divides the string into substrings, separated by the delimiter. The substrings are returned as string array. The delimiter(s) are not included in the returned string array. Divides the string into substrings, separated by the delimiter. The substrings are returned as string array. The delimiter(s) are not included in the returned string array. The resulting array is limited to the provided limit. Divides the string into substrings, separated by the delimiter. The substrings are returned as string array. If the regular expression delimiter specifies capturing groups, the captured expressions will be included in the returned string array. Divides the string into substrings, separated by the delimiter. The substrings are returned as string array. If the regular expression delimiter specifies capturing groups, the captured expressions will be included in the returned string array. The resulting array is limited to the provided limit. Examples import System; 12string fox = "Fox";Console.log(fox.split()); // [ "Fox" ] Explode string into individual characters 1234import System; string fox = "Fox";Console.log(fox.split("")); // [ "F", "o", "x" ] Comma Separated Values 1234import System; string csv = "Mike,George,Rick";Console.log(csv.split(",")); // [ "Mike", "George", "Rick" ] Reversing a String 1234import System; string text = "The quick brown fox.";Console.log(text.split("").reverse().join("")); // ".xof nworb kciuq ehT" Comma Separated Values 123456import System; string csv = "Mike,George,Rick";Console.log(csv.split(",", 1)); // [ "Mike" ]Console.log(csv.split(",", 2)); // [ "Mike", "George" ]Console.log(csv.split(",", 3)); // [ "Mike", "George", "Rick" ] Comma Separated Values 1234import System; string csv = "Mike,George,Rick";Console.log(csv.split(/,/)); // [ "Mike", "George", "Rick" ] Capturing Groups to Capture Delimiter 123456789import System; string message = "a,b,c"; // Without capturing groupConsole.log(message.split(/,/)); // [ 'a', 'b', 'c' ] // With capturing groupConsole.log(message.split(/(,)/)); // [ 'a', ',', 'b', ',', 'c' ] Comma Separated Values 123456789import System; string csv = "Mike,George,Rick"; // Without limitConsole.log(csv.split(/,/)); // [ "Mike", "George", "Rick" ] // With limitConsole.log(csv.split(/,/, 2)); // [ "Mike", "George" ] Capturing Groups to Capture Delimiter 123456789import System; string message = "a,b,c"; // Without capturing groupConsole.log(message.split(/,/)); // [ 'a', 'b', 'c' ] // With capturing groupConsole.log(message.split(/(,)/)); // [ 'a', ',', 'b', ',', 'c' ] Share HTML | BBCode | Direct Link