Created
January 27, 2021 03:14
-
-
Save portal7/c85f56a207ee0f94e03549d59552ce39 to your computer and use it in GitHub Desktop.
First Character of a sentence
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
String name = "University of Warwick"; | |
printInitials(name); | |
} | |
static void printInitials(String name) | |
{ | |
if (name.Length == 0) | |
return; | |
// Since touuper() returns int, | |
// we do typecasting | |
Console.Write(Char.ToUpper(name[0])); | |
// Traverse rest of the string and | |
// print the characters after spaces. | |
for (int i = 1; i < name.Length - 1; i++) | |
if (name[i] == ' ') | |
Console.Write(" " + Char.ToUpper(name[i + 1])); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment