+ Start a Discussion
grandak koygrandak koy 

Replace spaces in string

I need to remove spaces after i assign my variable:

 TeamName = FirstName + '.' + LastName + '-TeamMember';

How can I remove spaces when there is a space in the last name or first name: ex. First name: Jon James, Last name: robinson it shows up like this: Jon James.RobinsonTeamMember I want it to look like: JonJames.RobinsonTeamMember

 
Best Answer chosen by grandak koy
Raj VakatiRaj Vakati
Here is wrong. It will be TeamGrab.FirstName
 
AccountInfo.TeamName = TeamGrabFirstName+ '.' + Teamgrab.LastName+ ’TeamMember’; //changedfrom@

And the second reason is there is no point of setting the same value again for TeamName two times ... 

replace will work .. 

All Answers

Raj VakatiRaj Vakati
String TeamName = FirstName + '.' + LastName + '-TeamMember';

 TeamName= TeamName.replaceAll( '\\s+', '');

 
Raj VakatiRaj Vakati
No .. Change it as below 
 
RESTaccountInfoService.AccountInformationWrapper AccountInfo = new RESTaccountInforService.AccountInformationWrapper();

	AccountInfo.firstName = TeamGrab.FirstName;
	AccountInfo.lastName = TeamGrab.LastName;
	AccountInfo.TeamName= TeamGrab.FirstName+ '.' + TeamGrab.LastName+ '@lgs.com'.replaceAll('\\s+', '');

 
grandak koygrandak koy
Okay I will, but What is the difference?
Raj VakatiRaj Vakati
Can you share the old code if you have .. If i recall the old code you are not setting the values correctly 
grandak koygrandak koy
RESTaccountInfoService.AccountInformationWrapper AccountInfo = new RESTaccountInforService.AccountInformationWrapper();

        AccountInfo.firstName = TeamGrab.FirstName;
        AccountInfo.lastName = TeamGrab.LastName;

                AccountInfo.TeamName = TeamGrabFirstName+ '.' + Teamgrab.LastName+ ’TeamMember’; //changedfrom@
                AccountInfo.TeamName= AccountInfo.TeamName.replace(‘ ‘, ‘’);

old code above
Raj VakatiRaj Vakati
Here is wrong. It will be TeamGrab.FirstName
 
AccountInfo.TeamName = TeamGrabFirstName+ '.' + Teamgrab.LastName+ ’TeamMember’; //changedfrom@

And the second reason is there is no point of setting the same value again for TeamName two times ... 

replace will work .. 
This was selected as the best answer