Saturday, 16 July 2011

How to remove unwanted spaces in string for asp.net

Hi This Is Saleem


How to  remove white spaces between two words or in a string,Mainly freshers will struggle here unnecessarily they waste time.So rather wasting time we can utilize this code........

For C# Coding

First We Have Declare the Name-space Like   

using System.Text.RegularExpressions;

After Button Click Event or Any Event U Wish To

        string myString = txtSearchbyname.Text.Trim();
        Regex regulEx = new Regex(@"[\s]+");
        BO.Searchbyname = regulEx.Replace(myString, "");


This Code Will Help U to Remove Any Number Of White Spaces

Ex: Sachin  Ramesh     Tendulkar
Output : SachinRameshTendulkar

If We Want To Have Only One Space,For That Code Is

  string myString = txtSearchbyname.Text.Trim();
        Regex regulEx = new Regex(@"[\s]+");
        BO.Searchbyname = regulEx.Replace(myString, " ");




Ex: Sachin  Ramesh     Tendulkar
Output: Sachin Ramesh Tendulkar


Please Post Comments, If This Blog Helps You.........................

http://www.hardwinsoftware.com
'