String Manipulation in C#: Part 2
hive-196387·@leoumesh·
0.000 HBDString Manipulation in C#: Part 2
<div class="text-justify">
<center></center>
<center>[Image Source](https://witscad.com/course/csharp-basics/chapter/string-manipulations)</center>
In my previous tutorial we saw a basic introduction to string and various in-built functions that can be used to perform operation and manipulation on C# strings. In this tutorial, we are gonna discuss other some key concepts in string operations that you may come across in C#. One of the key concept in string operation is **String Interpolation** that was introduced in the year 2014 in C# version 6. It provides a more convenient and human readable approach to writing code by allowing us to substitute a value of string into a placeholder. Allowing this would save a chunk of time, memory allocation which would have been caused due to string concatenation. Lets see a simple example of this one:
```
using System;
class Program
{
static void Main()
{
int age = 25;
string name = "Peter";
Console.WriteLine($"My name is {name} and I am {age} years old.");
}
}
```
<hr>
If you run this code, you will get the following output:

See how much easier it is to write and debug a code using this approach. You need to use **"$"** sign while interpolating string and then **"{}"** brackets while substituting a value.
Another thing we want to look on is accessing a strings. We can do this by using an index number of string inside a **"[]"** brackets. If we run the code `Console.WriteLine(name[3]);` then we will get the output **e** as index always starts from 0. We can also use function called `IndexOf` to get the index value of a characters in a string.
```
using System;
class Program
{
static void Main()
{
int age = 25;
string name = "Peter";
Console.WriteLine($"My name is {name} and I am {age} years old.");
Console.WriteLine(name[3]);
Console.WriteLine(name.IndexOf("t"));
}
}
```
You can get the corresponding output for this code:

The last thing we wanna see about is using special characters like double quotes inside a double quotes. String should always be written inside a double quote in C# and if you want to write a string that contains double quote inside it then you can use backslash escape character.
```
using System;
class Program
{
static void Main()
{
string message = "Sometimes this process is also referred to as \"vaporization\".";
Console.WriteLine(message);
}
}
```
If you try to run the code without using backslash character(\) then you will get the error as compiler will misunderstand the syntax for the string. Lets see how to print a statement that contains **'s** inside a string in C#. For this you need to use single backslash(\) as:
```
using System;
class Program
{
static void Main()
{
string message = "Sometimes this process is also referred to as \"vaporization\".";
Console.WriteLine(message);
string message2 = "It\'s known as vaporization.";
Console.WriteLine(message2);
}
}
```
The output for this code is:

There are other special useful escape characters in C# that we will see as we go along the tutorial like New line (\n), backspace(\b), tab(\t).
<h4>**Link to other C# posts**</h4>
1. [Introduction to C# and .NET](https://hive.blog/hive-196387/@leoumesh/introduction-to-c-and-net)
2. [String Manipulation in C#](https://hive.blog/hive-196387/@leoumesh/string-manipulation-in-c)
</div>👍 leoumesh, kingfadino, andyjim, sharpshot, ewkaw, racibo, voitaksoutache, oladamola, logic, steemcleaners, spaminator, thepeakstudio, tomiscurious, votehero, msp-makeaminnow, voter002, voter003, voter000, we-are-palcoin, we-are, fatman, hivewatchers, lemouth, steemstem-trig, steemstem, roelandp, dna-replication, stemsocial, minnowbooster, howo, aboutcoolscience, robotics101, walterjay, aidefr, kenadis, r00sj3, greengalletti, inibless, valth, dhimmel, oluwatobiloba, helo, tsoldovieri, abigail-dantes, splash-of-angs63, sco, intrepidphotos, emiliomoron, dexterdev, geopolis, charitybot, melvin7, francostem, gadrian, de-stem, deholt, temitayo-pelumi, stem.witness, crowdwitness, krrizjos18, sunshine, metabs, techslut, sustainablyyours, alexander.alexis, alexdory, pboulet, pinkfloyd878, curie, joeyarnoldvn, samminator, madridbg, cyprianj, nattybongo, walterprofe, noelyss, profwhitetower, enzor, lpv, croctopus, satren, charitymemes, doctor-cog-diss, holoferncro, ohamdache, videosteemit, cliffagreen, aries90, qberry, cheese4ead, talentclub, drricksanchez, merit.ahama, belug, boxcarblue, empath, investingpennies, zyx066, greddyforce, softa, nateaguila, dawnoner, lukasbachofner, justyy, rocky1, hetty-rowan, fineartnow, bscrypto, vcclothing, littlesorceress, swayzilla, evagavilan2, newilluminati, azj26, justfavour, michelle.gent, yadamaniart, felt.buzz, superlotto, bil.prag, cryptocoinkb, multifacetas, steemstorage, cryptofiloz, altleft, torico, dynamicrypto, fantasycrypto, baboz, tfeldman, coindevil, ahmedsy, didic, musicvoter2, bflanagin, steemean, matilei, bipolar95, federacion45, cryptononymous, steveconnor, bennettitalia, cakemonster, rem-steem, instagram-models, ayee11, clpacksperiment, rhemagames, rt395, princessmewmew, adelepazani, jjerryhan, bedazzled, ledgar, bartosz546, utube, monica-ene, quinnertronics, omarrojas, atexoras.pub, pogier, modernzorker, thelordsharvest, amphlux, braveboat, steemvault, photohunt, zipporah, armandosodano, hairgistix, baltai, soylegionario, cloh76, pipiczech, neumannsalva, meno, therising, minerthreat, palasatenea, the.success.club, tggr, whywhy, yozen, blingit, vickoly, doodleaday, the-burn, arunava, jayna, pandasquad, trisolaran, hiveonboard, mobbs, eliel, stayoutoftherz, raj808, putu300, steemcryptosicko, dcrops, sidalim88, yixn, bitrocker2020, gunthertopp, laxam, kgakakillerg, kristall97, epicdice, the100, meritocracy, cryptosneeze, failingforwards, seinkalar, dev.maverick, metroair, sunsea, marc-allaria, takowi, kylealex, r-nyn, tawadak24, callmesmile, humbe, dreamm, t-nil, oscarina, communitybank, hopestylist, driptorchpress, juancar347, sportscontest, russellstockley, qwerrie, kharrazi, serylt, enjar, neneandy, acgalarza, detlev, maverickfoo, gabrielatravels, goodcontentbot, aichanbot, jijisaurart, anneporter, gloriaolar, hive-199963, lichtkunstfoto, kiemurainen, xeldal, rmach, mcsvi, goblinknackers, growandbow, ibt-survival, robibasa, reggaesteem, mproxima, sanderjansenart, holovision.cash, adol, enki, killerbot, pladozero, jerrybanfield, bigtakosensei, juecoree, stem-espanol, uche-nna, hivelist, hk-curation, wasined, llunasoul, carilinger, iamphysical, ydavgonzalez, miguelangel2801, tomastonyperez, elvigia, hmayak, acont, fran.frey, aleestra, giulyfarci52, aqua.nano, mey12, lorenzor, ufv, azulear, delpilar, josedelacruz, erickyoussif, andrick, reinaseq, alfonzoasdrubal, newton666, zeruxanime, ganjafarmer, psicoluigi, migka, zydane, hive-169313, liquidocelotytt, buttcoins, aiziqi, capp, ubaldonet, beerlover, gribouille, kieranstone, nfttunz, eric-boucher, robertbira, ajfernandez, lk666, cyemela, eternalsuccess, cyrusemerson, endopediatria, ennyta, bluefinstudios, m1alsan, careassaktart, nyxlabs, gamersclassified, futurekr, amestyj, tecnotronics, bpcvoter4, endhivewatchers,