Solved

Remove all spaces in c#

Posted on 2014-02-06
4
257 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

726 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