function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Taha HaiderTaha Haider 

How do i separate strings in a Text field??

How do i separate strings in a Text field??

"Taha Haider"

I want break this name into 2 sections.

1:Taha
2:Haider
Scott KostojohnScott Kostojohn
You can use the split method of the String class to do this. Something like:
 
String toSplit = 'Albert Einstein';

List<String> nameParts = toSplit.split(' ');

String firstName = nameParts[0];
String lastName = nameParts[1];



 
Taha HaiderTaha Haider
I want to do this with formula field
Maharajan CMaharajan C
Hi Taha,

Try like below: (Replace the Name in below with your field name)
"1:" & LEFT(Name,(FIND(" ",Name))) & BR() & "2:" & RIGHT(Name,(FIND(" ",Name)))

Thanks,
Maharajan.C

 
Suraj Tripathi 47Suraj Tripathi 47
Hi Taha Haider,

Try this:
SUBSTITUTE(Name , " ", "")

Please Mark it as Best Answer if it helps.

Thanks!
Taha HaiderTaha Haider
Maharajan.C no its not working
Suraj Tripathi47 nop its not wokring
Maharajan CMaharajan C
Try the below one:
 
"1:"  &  LEFT(Name,(FIND(" ",Name))) & BR() & "2:" & RIGHT(Name,LEN(Name) - FIND(" ", Name))

Thanks,
Maharajan.C
Suraj Tripathi 47Suraj Tripathi 47

Hi Taha Haider,

If you want to split this string in two section then you can split that string in two different fields ,lets take a custom field called name and the value on this field can be separated in firstname and lastname.You can try this:
 

If( CONTAINS(Name__c, " "), LEFT( Name__c ,FIND(" ", Name__c )), Name__c )  - for First Name
If( CONTAINS(Name__c, " "), MID( Name__c , FIND(" ", Name__c ), LEN(Name__c )), null) - for LastName
 

Thanks
 

Taha HaiderTaha Haider
Suraj Tripathi47 

This one is helpfull 
If( CONTAINS(Name__c, " "), LEFT( Name__c ,FIND(" ", Name__c )), Name__c )  - for First Name If( CONTAINS(Name__c, " "), MID( Name__c , FIND(" ", Name__c ), LEN(Name__c )), null) - for LastName

But i only want Firstname and Lastname not the mid one 
For example: Chloe Chloeeee Smith
Firstname : Chloe
Lastname : Smith 
Dont show the mid name
Suraj Tripathi 47Suraj Tripathi 47

Hi Taha Haider,

Try this one,it will give you your expected Result:

If( CONTAINS(Name__c, " "), LEFT( Name__c ,FIND(" ", Name__c )), Name__c )  - for First Name
If( CONTAINS(Name__c, " "), RIGHT( Name__c ,FIND(" ", Name__c )), Name__c ) - for Last Name


And Please don't forget to Mark it as Best Answer,if it helps you.

Thanks

Taha HaiderTaha Haider
Its working but in some conditions its not working.
Name: Chloeeee Chloe Smith
Try this name.