String Manipulation in C#
In this blog, we gonna see basic introduction to C# and do some operations on those strings. Strings are data type for storing text and manipulating them. Strings in C# are enclosed within double quotation ("") and can contain letters, characters, special symbols, even spaces or a combination of these. System.string class has an object string in C# that can help us to perform operations on the strings.
Lets start with a simple program. The following program demonstrates how string is initialized and concatenated using + operator.
using System;
class Program
{
static void Main()
{
string text1 = "Hello";
string text2 = "World";
Console.WriteLine(text1 + " " +text2);
}
}
The output of the above program will be as below. Remember that I have added some whitespace in between the text.
Another way to do the same thing is to use concat function as:
string message = string.Concat(text1,text2)
Console.WriteLine(message);
It will show the same output as above but there will be no whitespaces between these two texts.
Another string operation we can do is changing the uppercase and lowercase of the letters. To convert to uppercase we can write Console.WriteLine(text1.ToUpper()); and to change to lowercase we can write Console.WriteLine(text2.ToLower());. It will show the output as:
Another operation we can do on string is replacing the text. Suppose we want to print "GreetingsWorld" instead of "HelloWorld". We can do the same by doing: Console.WriteLine(message.Replace("Hello", "Greetings"));.
The output is as below:
In the next post, I am gonna show you about some more string manipulation like string interpolation, accessing strings and using special characters like double quotes inside double quotes.
Link to other C# posts:
Leave String Manipulation in C# to:
Read more #code posts
Best Posts From Leo Umesh
We have not curated any of leoumesh's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From Leo Umesh
- The Tattoo of My Newborn Baby Girl Forever Inked on My Skin
- Long Weekend Food Feast With Wife
- String Manipulation in C#: Part 2
- String Manipulation in C#
- Introduction to C# and .NET
- Weekend Escape To Falls
- Evening Barbecue With Favourite Beer 🍺 🍻
- NumPy Broadcasting
- Summer BBQ
- Review of "The Day of The Jackal" Series
- Wonders of Wave Rock, Western Australia
- Trying To Make Authentic Chicken Dum Biryani At Home
- Beautiful Ocean Lookout in South West Australia
- Esperance: Hidden Paradise of Western Australia
- Cruising Through Blue Haven Beach
- My First Tattoo
- Exploring Flavoursome Veggie Indian Cuisines
- Australia's Popular Drink: Homemade
- An Everlasting Flowers
- Unexpected Rainbow At Wellington Dam, Western Australia