Remove all spaces in c#

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

ksd123Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
James AtkinConnect With a Mentor Senior Principle Software EngineerCommented:
You could use:
userobj.registrationnumber=custobj.registrationnumber.Replace(" ", ""); 

Open in new window


James
0
 
Barry CunneyConnect With a Mentor Commented:
public class UserMapp
{

public void Map(user userobj, customer custobj)
{

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

}

}

Open in new window

0
 
AndyAinscowFreelance programmer / ConsultantCommented:
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
 
ksd123Author Commented:
Thank  you all
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.