- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Print first letter of each word in a string in C#
Let’s say the string is −
string str = "Never Give Up!";
Firstly, split each word −
string[] strSplit = str.Split();
Now, loop through each word and use the substring method to display the first letter as shown in the following code −
Example
using System; public class Program { public static void Main() { string str = "Never Give Up!"; Console.WriteLine("Initial String= "+str); Console.WriteLine("Displaying first letter of each word..."); string[] strSplit = str.Split(); foreach (string res in strSplit) { Console.Write(res.Substring(0,1)); } } }
Output
Initial String= Never Give Up! Displaying first letter of each word... NGU
Advertisements