Splitting a string by some delimiter is a very common task. For example, we have a comma separated list of items from a file and we want individual items in an array.
Almost all programming languages, provide function split a string by some delimiter.
// Splits str according to given delimiters. // and returns next token. It needs to be called // in a loop to get all tokens. It returns NULL // when there are no more tokens. char * strtok(char str, const char *delims);
Geeks for Geeks
In Java :
In Java, split() is a method in String class.
// expregexp is the delimiting regular expression; // limit is the number of returned strings public String split(String regexp, int limit); // We can call split() without limit also public String split(String regexp)
Geeks for-Geeks Geeks for Geeks
// regexp is the delimiting regular expression; // limit is limit the number of splits to be made str.split(regexp = "", limit = string.count(str))
['Geek1', 'Geek2', 'Geek3'] ['Geek1', '\nGeek2 \nGeek3']
This article is contributed by Aditya Chatterjee. If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Split() String method in Java with examples
- Python String | split()
- Python | Exceptional Split in String
- Python | K Character Split String
- Python - Split String of list on K character
- Python | Split given string into equal halves
- Python | Split flatten String List
- Python | Split string on Kth Occurrence of Character
- Python program to split and join a string
- Python | Split string into list of characters
- Python | String Split including spaces
- Python | Split multiple characters from string
- Split a string in equal parts (grouper in Python)
- Python | Split strings and digits from string list
- Python | Rear stray character String split
- Python | Split string in groups of n consecutive characters
- Python | Split CamelCase string to individual strings
- Python | Pandas Split strings into two List/Columns using str.split()
- Split the string into minimum parts such that each part is in the another string
- Python | Ways to split a string in different ways