Solved

Remove all spaces in c#

Posted on 2014-02-06
4
249 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can I build my own IDE using ASP.NET MVC? 2 34
Error in query expression 3 37
ASP.NET 5 Templates 2 68
Visual Studio TFS - how do I check in my code? 2 30
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

862 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now