- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
C# Program to convert first character uppercase in a sentence
Let us say the following is your string −
String str = "Welcome to our website!";
Create a char array of the string included above using the ToCharArray() method:
char []ch = str.ToCharArray();
To convert the first character to uppercase −
if (ch[i] >= 'a' && ch[i] <= 'z') { // Convert into Upper-case ch[i] = (char)(ch[i] - 'a' + 'A'); }
Example
You can try to run the following code to convert first character uppercase in a sentence.
using System; class Demo { static String MyApplication(String str) { char []val = str.ToCharArray(); for (int i = 0; i < str.Length; i++) { if (i == 0 && val[i] != ' ' || val[i] != ' ' && val[i - 1] == ' ') { if (val[i] >= 'a' && val[i] <= 'z') { val[i] = (char)(val[i] - 'a' + 'A'); } } else if (val[i] >= 'A' && val[i] <= 'Z') val[i] = (char)(val[i] + 'a' - 'A'); } String s = new String(val); return s; } public static void Main() { String str = "Welcome to our website!"; Console.Write(MyApplication(str)); } }
Output
Welcome To Our Website!
- Related Articles
- C Program to convert first character uppercase in a sentence
- Java Program to convert first character uppercase in a sentence
- C# Program to replace a character with asterisks in a sentence
- Program to reverse a sentence words stored as character array in C++
- Convert a String to Uppercase in C
- Count spaces, uppercase and lowercase in a sentence using C
- Swift Program to Convert a String to Uppercase
- C Program to read and write character string and sentence
- Write a C program to convert uppercase to lowercase letters without using string convert function
- C# Program to Convert Character case
- Java program to convert a string to lowercase and uppercase.
- Get field value and convert a particular character from it to uppercase with MySQL
- C++ program to convert kth character to lowercase
- PHP program to find the first word of a sentence
- Java program to swap first and last characters of words in a sentence

Advertisements