text: Contiguous subsegments of a string having distinct subsequent characters | C # implementation of the approach ; Function that prints the segments ; New array for every iteration ; Check if the character is in the array ; Driver code
code: using System ; using System . Collections . Generic ; class GFG { static void sub_segments ( String str , int n ) { int l = str . Length ; for ( int x = 0 ; x < l ; x += n ) { String newlist = str . Substring ( x , n ) ; List < char > arr = new List < char > ( ) ; foreach ( char y in newlist . ToCharArray ( ) ) { if ( ! arr . Contains ( y ) ) arr . Add ( y ) ; } foreach ( char y in arr ) Console . Write ( y ) ; Console . WriteLine ( ) ; } } public static void Main ( String [ ] args ) { String str = " geeksforgeeksgfg " ; int n = 4 ; sub_segments ( str , n ) ; } }