Program to print the initials of a name with the surname | C # program to print the initials of a name with the surname ; to remove any leading or trailing spaces ; to store extracted words ; forming the word ; when space is encountered it means the name is completed and thereby extracted ; printing the first letter of the name in capital letters ; for the surname , we have to print the entire surname and not just the initial string " t " has the surname now ; first letter of surname in capital letter ; rest of the letters in small ; printing surname ; Driver Code
using System ; class Initials { public static void printInitials ( string str ) { int len = str . Length ; str = str . Trim ( ) ; String t = " " ; for ( int i = 0 ; i < len ; i ++ ) { char ch = str [ i ] ; if ( ch != ' ▁ ' ) { t = t + ch ; } else { Console . Write ( Char . ToUpper ( t [ 0 ] ) + " . ▁ " ) ; t = " " ; } } string temp = " " ; for ( int j = 0 ; j < t . Length ; j ++ ) { if ( j == 0 ) temp = temp + Char . ToUpper ( t [ 0 ] ) ; else temp = temp + Char . ToLower ( t [ j ] ) ; } Console . WriteLine ( temp ) ; } public static void Main ( ) { string str = " ishita ▁ bhuiya " ; printInitials ( str ) ; } }