C# Program to Find the First Characters of Each Word in a String
Most of the IT companies check the coding skills and problem-solving skills as well along with the theoretical interview questions. Sometimes you are free to write the pseudo code and sometimes you are asked to write the complete program either on any paper or any editor.
This question is asked in the coding interview to write the program. Here you can find the program as well as a live running program so that you can test the program immediately.
Question:
How can you find and return the first character of each word in the capital letter for a given sentence? Write a program for the same.
C# Program To Find the First Characters of Each Word in a String
// Author : Tech Point Fundamentals
// Website : www.techpointfunda.com
// Channel : https://www.youtube.com/c/TechPointFundamentals
// Demo : Finding First Character of Each Word
using System;
public class Program
{
public static void Main()
{
string inputString = "Tech Point Fundamentals";
Console.WriteLine("Input String : " + inputString);
Console.WriteLine("First Characters of Each Word : ");
FirstCharacterOfWords(inputString);
}
public static void FirstCharacterOfWords(string inputString)
{
if (!string.IsNullOrWhiteSpace(inputString))
{
string[] wordArray = inputString.Split(' ');
foreach (string item in wordArray)
{
Console.WriteLine(String.Format("{0} : {1}", item, item.Substring(0, 1).ToUpper()));
}
}
}
}
Output:
Input String : Tech Point Fundamentals
First Characters of Each Word :
Tech : T
Point : P
Fundamentals : F
No comments:
Post a Comment
Please do not enter any HTML. JavaScript or spam link in the comment box.