Solved

Remove all spaces in c#

Posted on 2014-02-06
4
254 Views
Last Modified: 2014-02-07
Hi Experts,

I have below mapping class and from client side will get registrationnumber data in the form of  123 456 7899 and should trim all the spaces (1234567899) and save it to database.what is best way to achieve this?

public class UserMapp
{

public void Map(user userobj, customer custobj)
{

userobj.registrationnumber=custobj.registrationnumber; 

}

}

Open in new window

0
Comment
Question by:ksd123
4 Comments
 
LVL 4

Accepted Solution

by:
jatkin earned 100 total points
ID: 39838403
You could use:
userobj.registrationnumber=custobj.registrationnumber.Replace(" ", ""); 

Open in new window


James
0
 
LVL 17

Assisted Solution

by:Barry Cunney
Barry Cunney earned 100 total points
ID: 39838409
public class UserMapp
{

public void Map(user userobj, customer custobj)
{

userobj.registrationnumber=custobj.registrationnumber.ToString().Replace(" ", string.empty); 

}

}

Open in new window

0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 39838413
In addition - don't forget that is throwing information away which you can not restore unless the format is always (not 999,999 from a million times) the same.

I've experienced similar, this happens always and then later very occasionally it is different, how do we restore it to the original format.  Ooops!!!!!
0
 

Author Closing Comment

by:ksd123
ID: 39843700
Thank  you all
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question