Replacing a substring starting with a specific character

Kurt Muller asked on June 3, 2020 13:57

Hi there

I have a number of values being returned from an array and want to update a sub string of each value as follows:

name@company.com

name@company.dev

name@company.net

I want to replace the "." in each value as well as the next 3 letters afterwards. Is that possible using a macro? Something like: CustomContent.GetUser[0].Email.Replace(CustomContent.GetUser[0].Email.Substring("." + 2 characters afer), "newvalue")

Correct Answer

David te Kloese answered on June 3, 2020 14:33

You could use something as:

{% "name@company.com".Substring(0, "name@company.com".LastIndexOf(".")) #%}

This will find the last . in your string.

This lastindex of makes sure it also works for something like first.lastname@company.com

This will however not work for domains in for instance the UK... email@company.co.uk

0 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.