Skip to main content


Showing posts from December, 2013

How to swap words in a string using LINQ in C#

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.

How to get all Uppercase or Lowercase word using LINQ in C#

In this post, I'll show how you can filter out uppercase or lowercase words in a string
Code to find uppercase or lowercase words in given string:
var str = "Test String With lower And UPPER Case";
//Find all Uppercase words var upperItems = str.Split(' ')                 .Where(s => String.Equals(s, s.ToUpper(), StringComparison.Ordinal));
//Find all Lowercase words var lowerItems = str.Split(' ')                 .Where(s => String.Equals(s, s.ToLower(), StringComparison.Ordinal));
Output: You can check upperItems contains one word “UPPER” and lowerItems contains one word as well i.e. “lower”

How to get selected text or value from dropdown list using jquery

In this post, I'll show how you can get the selected text and selected value of dropdown using jQuery. Dropdown can be ASP.Net dropdown or HTML dropdown.
Let’s define one dropdown and button:
<!--Dropdown can be either of ASP.Net --> <asp:DropDownListID="ddlGender"runat="server"> <asp:ListItemValue="-1">-Select-</asp:ListItem> <asp:ListItemValue="1">Male</asp:ListItem> <asp:ListItemValue="2">Female</asp:ListItem

Cleanup failed to process the following paths. pristine text not present.

While working with Subversion you may face error as “Cleanup failed to process the following paths…The system cannot find the file specified.”
Reason: This error occurs when certain pristine file doesn’t exist in your SVN directory; reason may be corrupted repository or due to Subversion is upgraded to new latest version, due to which you may get error while trying to clean up the repository.
Solution: To solve the error there are two possible options, I came across (although there may be another option as well): ·First option is create missing file with nothing in it (i.e. blank file) and then cleanup should work. For example you are getting error of missing file ‘5dd653fb079a95e1a459384a5e78e37ca3350d8d.svn-base’, just create the blank file with this name on path shown in error. ·Another option is checkout the code in new directory and use Beyond Compare to make sure that old and new directories are in synch.