1String string = "004-034556";
2String[] parts = string.split("-");
3String part1 = parts[0]; // 004
4String part2 = parts[1]; // 034556
5
1String yourString = "Hello/Test/World";
2String[] strings = yourString.split("/" /*<- Regex */);
3
4Output:
5strings = [Hello, Test, World]
1string phrase = "The quick brown fox jumps over the lazy dog.";
2string[] words = phrase.Split(' ');
3
4foreach (var word in words)
5{
6 System.Console.WriteLine($"<{word}>");
7}
8
1//Java program to show the use of Split method (Java 8 and above)
2public class SplitString{
3
4 public static void main(String[] args)
5 {
6 //Initialize the String which needs to be split
7 String str = "Enlighter";
8
9 //Use the Split method and store the array of Strings returned in a String array.
10 String[] arr = str.split("");
11
12 //Printing the characters using for-each loop
13 for(String character : arr)
14 System.out.print(char);
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}
1const str = 'The quick brown fox jumps over the lazy dog.';
2console.log(str.split(''));
3console.log(str.split(' '));
4console.log(str.split('ox'));
5> 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", "."]
6> Array ["The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog."]
7> Array ["The quick brown f", " jumps over the lazy dog."]