Best Funcs of String in C#

Taylan Can Hardal
3 min readJan 25, 2022

Hey everyone. I will explain functions which are best in C#. I use these functions all the time.

Contains

Firstly Contains func. Function that returns whether the searched string value is present or not in the entered string value.

Sample Code :

Console.WriteLine(“Please enter the word that you contain : “);

var containsValue = Console.ReadLine();

var contains = tempVariable.Contains(containsValue);

Console.WriteLine($”Contains : {contains}”);

Look like :

Ends With

The another important func is EndsWith func. This function determines to return string value’s last letter is same with string value that our last letter.

Sample Code :

Console.WriteLine(“Please enter the last letter you want to check : “);

var endsWithValue = Console.ReadLine();

var endWith = tempVariable.EndsWith(endsWithValue);

Console.WriteLine($”End With : {endWith}”);

Look like :

Index Of

The third func is IndexOf func. If there is a char in the string value we are looking for, it returns the first index of it.

Sample Code :

Console.WriteLine(“Please enter the char you want to check of first index : “);

var indexOf = Console.ReadLine();

var index = tempVariable.IndexOf(indexOf);

Console.WriteLine($”IndexOf : {index}”);

Look like :

Split

4. func is Split func. This func is kind a separator. It allows us to separate the sentence according to the char we have determined. For example, spaces. As in the sample codes.

Sample Code :

string[] subs = tempVariable.Split(‘ ‘);

Console.WriteLine();

foreach (var sub in subs)

{

Console.WriteLine($”Split : {sub}”);

}

Look like :

Substring

Final func is Substring func. This function is kind of separator like Split function, but this function returns us the string value only after the index you used as separator.

Sample Code :

Console.WriteLine(“Please enter the start index you want to : “);

var indexOf = Convert.ToInt32(Console.ReadLine());

var substring =tempVariable.Substring(indexOf);

Console.WriteLine($”Substring : {substring}”);

Look like :

If you want to learn all of the String Funcs you can check my GitHub repo

And Contact W/me

Also

taylancanh@gmail.com

bolŞans…

--

--

Taylan Can Hardal

Software Engineer @Turkcell. Savin’ the Earth. Somewhere