cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Siddz
Super User
Super User

Extracting text from a string

I have user display names in this format:

Last, First M DEPT REGION COUNTRY 
// Smith, Bob R ACCOUNTING WEST USA

I want to show the name in this format:

Last, First
// Smith, Bob

Here's my current expression (which is close, but it includes the middle initial):

first(split(item()?['Employee/DisplayName'],'DEPT'))
// Smith, Bob R

I'd like to get rid of everything after the first name, including the middle initial. I've tried indexOf() and substring(), but haven't been able to find the right combination. 

1 ACCEPTED SOLUTION

Accepted Solutions
abm
Super User
Super User

Hi @Siddz 

 

// Smith, Bob R

 

You could do a split with spaces and specify the index. Try the below.

 

split('Smith, Bob R',' ')[0]

split('Smith, Bob R',' ')[1]


Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog
Power Automate Video Tutorials

View solution in original post

2 REPLIES 2
abm
Super User
Super User

Hi @Siddz 

 

// Smith, Bob R

 

You could do a split with spaces and specify the index. Try the below.

 

split('Smith, Bob R',' ')[0]

split('Smith, Bob R',' ')[1]


Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog
Power Automate Video Tutorials
Siddz
Super User
Super User

Thanks, @abm!

 

Here's my final expression :

concat(split(item()?['Employee/DisplayName'],' ')[0], ' ', split(item()?['Employee/DisplayName'],' ')[1]) 
// Result: Smith, Bob

I added concat() to join the last name with the first name (with a space between the names).

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Users online (5,262)