TheRealLester
9
Q:

split string

# Default splits at whitespace
txt = "Welcome to the jungle, baby!"
txt.split()
# Output:
# ["Welcome", "to", "the", "jungle," "baby!"]

# You can specify where to split
txt = "Welcome to the jungle, baby!"
txt.split(", ")
# Output:
# ["Welcome to the jungle", "baby!"]
72
//split into array of strings.
var str = "Well, how, are , we , doing, today";
var res = str.split(",");
29
// bad example https://stackoverflow.com/questions/6484670/how-do-i-split-a-string-into-an-array-of-characters/38901550#38901550

var arr = foo.split(''); 
console.log(arr); // ["s", "o", "m", "e", "s", "t", "r", "i", "n", "g"]
16
var input = "How are you doing today?";
var result = input.split(" ");

// result is string[] {"How", "are", "you", "doing", "today?"}
16

var str = "How are you doing today?";

var res = str.split(" ");
 
7
var myString = 'no,u';
var MyArray = myString.split(',');//splits the text up in chunks
11
var str = 'It iS a 5r&e@@t Day.'
var array = str.split(" ");
print(array);

var str = 'It iS a 5r&e@@t Day.'
var array = str.split(" ",2);
print(array);
6
const str = 'The quick brown fox jumps over the lazy dog.';
console.log(str.split(''));
console.log(str.split(' '));
console.log(str.split('ox'));
> Array ["T", "h", "e", " ", "q", "u", "i", "c", "k", " ", "b", "r", "o", "w", "n", " ", "f", "o", "x", " ", "j", "u", "m", "p", "s", " ", "o", "v", "e", "r", " ", "t", "h", "e", " ", "l", "a", "z", "y", " ", "d", "o", "g", "."] 
> Array ["The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog."] 
> Array ["The quick brown f", " jumps over the lazy dog."]
3
const str = 'The quick brown fox jumps over the lazy dog.';

const words = str.split(' ');
console.log(words[3]);
// expected output: "fox"

const chars = str.split('');
console.log(chars[8]);
// expected output: "k"

const strCopy = str.split();
console.log(strCopy);
// expected output: Array ["The quick brown fox jumps over the lazy dog."]
0

Tags

New to Communities?

Join the community