HOw to get last but 1 Item from String Array

Digital Skids/Pallets;Total:;11.65;$477.65

Digital;11.65;$477.65

I have two different strings , Need to extract last but 1 in this case 11.65.
I need extract last but 1 item from array, any logic

Split(yourStr,“;”)(Split(yourStr,“;”).Length-2)

This will always take the second to last element from the array. It’s -2 because arrays are 0 index. So the first one has a length of 4 so it’ll take element 2 (the third element). The second one has a length of 3 so it’ll take element 1 (the second element)

@Chaitan

Stroutput=system.text.regularexpression.regex.match(inputstring,“(?<=;)\d{2}.\d{2}”).value

cheers

Hi,

FYI, another approach

Regex

System.Text.RegularExpressions.Regex.Match(yourString,"[^;]+(?=;)",System.Text.RegularExpressions.RegexOptions.RightToLeft).Value

TakeLast and First (if your project is Windows)

yourString.Split({";"c}).TakeLast(2).First()

SkipLast and Last (if your project is Windows)

yourString.Split({";"c}).SkipLast(1).Last()

Regards,

1 Like

Hi @Chaitan
Use the below Syntax in Assign activity:

InputString: "Digital Skids/Pallets;Total:;11.65;$477.65"
SplitArray: InputString.Split(";"c)
PenultimateItem: SplitArray(SplitArray.Length - 2)

Note: InputString is of DataType System.String. SplitArray is of DataType Array(System.String). PenultimateItem is of DataType System.String.

Hope it helps!!

1 Like

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