Print the first and last character of each word in a String | C # program to print the first and last character of each word in a String ; Function to print the first and last character of each word . ; If it is the first word of the string then print it . ; If it is the last word of the string then also print it . ; If there is a space print the successor and predecessor to space . ; Driver code
using System ; class GFG { static void FirstAndLast ( string str ) { int i ; for ( i = 0 ; i < str . Length ; i ++ ) { if ( i == 0 ) Console . Write ( str [ i ] ) ; if ( i == str . Length - 1 ) Console . Write ( str [ i ] ) ; if ( str [ i ] == ' ▁ ' ) { Console . Write ( str [ i - 1 ] + " ▁ " + str [ i + 1 ] ) ; } } } public static void Main ( ) { string str = " Geeks ▁ for ▁ Geeks " ; FirstAndLast ( str ) ; } }