Samar
0
Q:

string split

# 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
const str = 'Hello!';

console.log(Array.from(str)); //  ["H", "e", "l", "l", "o", "!"]
9
string = "A B C D"
string2 = "E-F-G-H"

# the split() function will return a list
stringlist = string.split() # if you give no arguments, it will separate by whitespaces by default
stringlist2 = string2.split("-", 3) # you can specify the maximum amount of elements the split() function will output
20
string = 'this is a python string'
wordList = string.split(' ')
5
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

New to Communities?

Join the community