Javatpoint Logo
Javatpoint Logo

LINQ to Strings

LINQ to strings is nothing but writing the LINQ queries on String to get the required data from the string sequence. In LINQ, we can write queries on strings along with traditional string functions and regular expressions to perform the required operations on strings using the LINQ.

Syntax of LINQ to Strings

The syntax of writing the LINQ queries is:

In the above syntax, we have written the LINQ query on String to get the distinct element.

Example of LINQ to Strings

Here is the example of writing the LINQ queries on String to split the String into words in C#.

In the above example, we have written the simple query in LINQ to split the string "str" into multiple words. Here "str" string object contains many spaces between words, and to remove these spaces, we use "StringSplitOptions.RemoveEmptyEntries" properties. In case if we use traditional coding, we need to write a lot of code to split the String and remove the spaces between words.

OUTPUT:

LINQ to Strings

This is how we can use LINQ queries on strings to get the required data from the strings.






Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA