Day 10: Strings Basic Handling

Leslie RamĂ­rez
2 min readDec 17, 2021

--

Hello there!! 👋👋👋 It’s our 10th coding winter day. Let’s talk about Strings, a simple sequence of Unicode characters like this paragraph. But let’s get into details.

String type

A string is an object of type String whose value is text. Internally, the text is stored as a sequential read-only collection of Char objects. A string literal is specified within double quotes:

We can perform some actions with the string type I’m going to share some of the basics:

String Concatenation

The + operator concatenates two strings:

String interpolation

A string preceded with the $ character is called an interpolated string. Interpolated strings can include expressions enclosed in braces:

Any valid C# expressions of any type can appear within the braces, and will be converted to a string.(Calling ToString method or equivalent).

Accessing characters within a string

A string’s indexer returns a single character of the given index. As with all functions that operate on strings, this is zero-indexed:

Searching within strings

The simplest methods for searching within strings are: StarWith, EndsWith, and Contains. These all return true or false:

The default is to perform a case-sensitive match using rules applicable to the current (localized) culture. The following instead performs a case-insensitive search using the invariant culture’s rules:

Manipulate strings

Before we learn that some of the common methods to manipulate Strings is unchangeable after they’re created, all the methods that manipulate a string return a new one.

So let’s do some basic manipulation:

Conclusions

The string is a reference type object, we have many methods to manipulate them as we need. If you want to learn more about it follow this link:

Strings — C# Programming Guide | Microsoft Docs

If you enjoyed this article, please hold down the clap button 👏👏👏 Don’t forget to follow our Coding winter Calendar. Have a wonderful day! 🧡 💛 💚🧡 💛 💚

--

--

Leslie RamĂ­rez

I am Microsoft MVP in the award category: Developers technologies, a professional with several years in software development specifically in .NET technology.