1String string = "004-034556";
2String[] parts = string.split("-");
3String part1 = parts[0]; // 004
4String part2 = parts[1]; // 034556
5
1const str = 'Hello!';
2
3console.log(Array.from(str)); // ["H", "e", "l", "l", "o", "!"]
1var myString = 'no,u';
2var MyArray = myString.split(',');//splits the text up in chunks
3
1foo = "A B C D"
2bar = "E-F-G-H"
3
4# the split() function will return a list
5foo_list = foo.split()
6# if you give no arguments, it will separate by whitespaces by default
7# ["A", "B", "C", "D"]
8
9bar_list = bar.split("-", 3)
10# you can specify the maximum amount of elements the split() function will output
11# ["E", "F", "G"]
1public class SplitExample2 {
2 public static void main(String args[])
3 {
4 String str = "My name is Chaitanya";
5 //regular expression is a whitespace here
6 String[] arr = str.split(" ");
7
8 for (String s : arr)
9 System.out.println(s);
10 }
11}
1string = 'James Smith Bond'
2x = string.split(' ') #Splits every ' ' (space) in the string to a list
3# x = ['James','Smith','Bond']
4print('The name is',x[-1],',',x[0],x[-1])