Tag: string

How to Populate XDocument from String in C# ?

To populate the XDocument from a string in C# , we can use the Parse method defined in the XDocument class. Below is a sample code snippet that demonstrates how to populate XDocument from string in C#. How to Populate XDocument from String in C# ?

Concatenate or Join a string Array using LINQ in C#

Want to join the items inside the string array say with, delimiter using LINQ in C#? It’s pretty easy. Below is a sample code snippet demonstrating in easy steps on how to concatenate a string array using LINQ in C#? Concatenate or Join a string Array using LINQ in C#

Case insensitive string comparison for Contains in C#

When using the string.contains method , the comparison is done based on the exact string that is passed as parameter. In this case , the comparison is case-sensitive. using System; namespace ACConsoleApp { class Program { static void Main(string[] args) { string input = “This is a WeLcome string”; var output = input.Contains(“Welcome”); Console.WriteLine(output); Console.ReadLine(); } } } In the above code snippet , the…

Count the Occurrences of String within another String in C#

Do you want to find the number of occurrences of a string within a string in C#? This article will explain how to do it. How would you count occurrences of a string within a string (C#)? For example, assume that the main string is “Abundantcode is a programming, soucrecode, technology related website”. If we need to find the number of occurrences of the comma…

How to embed Quotes in a String in C# ?

You can embed Quotes within a string in C# by using the escape sequence character . Just prefix the quotes with a back slash (\). How to embed Quotes in a String in C# ? Below is a sample sourcecode demonstrating How to embed Quotes in a String in C# ?

How to embed quotes inside string in C# ?

If you want to embed quotes within a string in C# , you can use the escape sequence \ followed by the double quotes. How to embed quotes inside string in C# ? Below is a sample sourcecode demonstrating How to embed quotes inside string in C# .

How to Get the Maximum value from a List of String using LINQ in C# ?

In one of the previous article , we explained how to get the maximum value from a list of integer using LINQ query in C# . What happens when the column is a string instead of integer ?. Below are 2 possibilities on how to get the maximum value from a list of string. How to Get the Maximum value from a List of String…

How to get last four characters from a string in C#?

This post will provide a simple tip showing how you can get the last 4 characters from a string in C#. How to get last four characters from a string in C#? Assume that you have a string that contains the value “CodersEditor.com” and you wish to get .com from the string and display it. Below is a sample code snippet demonstrating how you can…

How to convert a string to integer in C# ?

You can convert a string to integer in C# using the following functions 1. Int32.Parse / int.Parse 2. Convert.ToInt32 3. Int.TryParse() How to convert a string to integer in C# ? Below is a sample sourcecode demonstrating the usage of the above functions The advantage of using the int.tryparse is that when the string (str) in the above example is a invalid number , a…