Split the string into substrings using delimiter | C # implementation to split String into substrings on the basis of delimiter ; function to split String into subStrings on the basis of delimiter and return the subStrings after split ; to count the number of split Strings ; adding delimiter character at the end of ' str ' ; length of ' str ' ; traversing ' str ' from left to right ; if str [ i ] is not equal to the delimiter character then accumulate it to ' word ' ; if ' word ' is not an empty String , then add this ' word ' to the array ' substr _ list [ ] ' ; reset ' word ' ; return the splitted Strings ; Driver code
using System ; using System . Collections . Generic ; class GFG { static List < String > splitStrings ( String str , char dl ) { String word = " " ; int num = 0 ; str = str + dl ; int l = str . Length ; List < String > substr_list = new List < String > ( ) ; for ( int i = 0 ; i < l ; i ++ ) { if ( str [ i ] != dl ) { word = word + str [ i ] ; } else { if ( ( int ) word . Length != 0 ) { substr_list . Add ( word ) ; } word = " " ; } } return substr_list ; } public static void Main ( ) { String str = " geeks ; for ; geeks " ; char dl = ' ; ' ; List < String > res = splitStrings ( str , dl ) ; foreach ( String x in res ) { Console . WriteLine ( x ) ; } } }