Replace everything after certain character

  • 78 Views
  • Last Post 06 July 2018
  • Topic Is Solved
sara posted this 04 July 2018

Hi all,

I have an email address "shelon1986"<shelon0619@xyz.com>. How to remove""shelon1986" and get only "shelon0501@xyz.com" as output.

 

Order By: Standard | Newest | Votes
Vladimir Dimitrijevic posted this 06 July 2018

Hi Sara,

Here is some C# example you can use to retrieve only values between "<" and ">":

            string st = "\"shelon1986\"<shelon0619@xyz.com>";
            int from = st.IndexOf("<") + 1;
            int to = st.LastIndexOf(">");
            st = st.Substring(from, to - from);

It will work if you create warning script rule on your field and add these lines of code. Instead of "st" use: Context.Field("ReplaceWithYourFieldName").Text;

Best regards,
Vladimir

Vladimir Dimitrijevic posted this 06 July 2018

Hi, 

Just to add code you will use in script rule, to make it easier for you:

            string st = Context.Field("ReplaceWithYourFieldName").Text;
            int from = st.IndexOf("<") + 1;
            int to = st.LastIndexOf(">");
            Context.Field("ReplaceWithYourFieldName").Text = st.Substring(from, to - from);

Best regards,
Vladimir

  • Liked by
  • sara
sara posted this 06 July 2018

Thank you Mr. Vladimir..! I did as you said and It works fine. Thank you very much

  • Liked by
  • Vladimir Dimitrijevic
Vladimir Dimitrijevic posted this 06 July 2018

Hi Sara, 

You're most welcome! I'm glad I helped.

Best regards,
Vladimir

Close