String manipulation to get customer name

Hi there,

I am scraping a customer name as part of a data table from a website for a bot that I am building and then use string manipulation to get the first and last name. This worked at first, but the bot fails if there is a middle name. For example:

The website field is called ‘name’ and will state the customer’s name as ‘Joe Blogs’ and so I used this code:
pDictionary(“Name:”).Trim.Split(" “c)(0) - First name
pDictionary(“Name:”).Trim.Split(” "c)(1) - Second name

I then use and assign activity to turn the above code into a variable of FirstName or SecondName.

The issue is, if the customer name is ‘Joe S Blogs’ or ‘Joe Steven Blogs’ then the second name of course lists the second name as ‘S/Steven’ rather than ‘Blogs’.

How would I make it so that the bot can tell if there is a middle name and has to exclude it? Customer details of course change on a case-by-case basis.

Apologies, I’m still new to this!

@dr1992

Try below expressions to fetch Last name.

  varName.SubString(varName.LastIndexOf(" ")).Trim

Here, varName holds Full Name.

1 Like

Thank you, I think this will work, though I am now running in to a new problem and so cannot check haha.

I’m having an issue with the ‘company name’ field on the website; some customers have a company, but if they don’t then the field doesn’t appear. Therefore, when it scrapes the data table, my assign ‘pCompanyName = pDictionary(“Company Name:”)’ throws out an error.

I put this in a trycatch in hopes it would skip it, but the error keeps arising. Any ideas?

@dr1992

May I know what error are you getting if you enclose it with Try Catch block.

Multiple Assign - Create Variables from Dictionary: Can not assign ‘pDictionary(“Company Name:”)’ to ‘pCompanyName’.

Actually I think I know the issue.

The datatable isn’t scraping if it has that field missing. Maybe I will need to scrape again and merge it…

Thanks for your help

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.