Swapping
of word inside a string using LINQ requires a small piece of code.
Requirement: For example you are
getting name of user as “FirstName
LastName”, but on UI you want to show name as “LastName FirstName”. In such scenario you can take help of LINQ
and swap two words like mentioned below:
var userName = "Sandeep Kumar";
//Swap FirstName and LastName.
userName
= string.Join(" ", userName.Split(' ').Reverse()).Trim();
|
Output: userName contains “Kumar
Sandeep” after words are swapped.
Comments
Post a Comment