How to Split String after Certain character

(Split(input.ToString,“R”)(1).ToString.Trim).Replace(“,”,“.”). I have written this to split string (C2019INR30045,67) after R character. It working fine. Sometimes I will have Input String as (C2019USD567,89). How to write Split string to extract characters after R or D.. I don’t know How to insert OR operator in order to split string. Please help

we can work with Regex e.g. with Groups

@Prathibabala An Alternate using the Split method :

Consider the input variable str = “C2019INR30045,67”

You can use the below expression in Assign Statement :

data = if(Split(str,"INR").Count>1,Split(str,"INR"),if(Split(str,"USD").Count>1,Split(str,"USD"),{}))

Where data is a variable of the type Array of String.

You can then check the data contains the Count 2, then get the data from both the parts in the below way :

if (data.Count=2)     //If Activity
    firstHalf = data(0)           //Assign Statement
    secondHalf - data(1)       // Assign Statement

Thank you Very Much

1 Like

Another solution is to use RegEx.Split() with the OR operator | in the regular expression.

data = RegEx.Split(input.ToString, "INR|USD")

The perk of this function is that it’s much easier to add additional currencies if you need it in the future.

data = RegEx.Split(input.ToString, "INR|USD|EUR|AUD")

Remember to import the namespace System.Text.RegularExpressions if you want to use RegEx.Split().

1 Like

_Ary = {“R”, “D”}
YourStr.Split(_Ary, StringSplitOptions.RemoveEmptyEntries)

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