String dynamic

Hi I need help. I have a string dynamic
example:

string A:“511 CRÉD. IVA POR DCTOS. ELECTRÓNICOS 13.936.911”
string A: "584 CANT.INT.EX.NO GRAV.SIN DER. CRED.FISCAL 25 "

I need to get the last number of the string
string A: 13.936.911
string A: 25

note: Always there is a space and then a number.

Hi @bosses.project ,

We could use simple split function like below and store the split strings into string array.

InputString = “511 CRÉD. IVA POR DCTOS. ELECTRÓNICOS 13.936.911”

InputString.Split(" "c)

input string should be string arr

Use For each loop and assign the item to your FinalNumber so last loop it will hold the desired number. Please refer the attached code for reference.


Split Demo.zip (2.4 KB)

Hello, You can also use regex with this : ( [0-9]+[.0-9]*) and take the last result of the list

Hi @bosses.project

Use this syntax in assign activity

Out_str = System.Text.RegularExpressions.Regex.Match(your_input_string_variable,"[.\d]+$").ToString

Out_str is string datatype and stores the last number from your input string
hope its solves your issue
Thanks,
Robin S

thank [kirankumar.mahanthi1](https://forum.uipath.com/u/kirankum

Thank you very much, but the string has a space at the end of the number.

Thank you.

It doesn’t help me because there are cases like this:

729 M3 COM. IEPD TRANSP. CARGA, LEY 19764/01 32.24
744 COMP. BASE TRANSP. CARGA, 20.493 393.190
745 COMP. VAR. TRANSP. CARGA, LEY 20.493 -57.017

You don’t need a For Each.

StringArr(StringArr.Length -1).ToString will always give you the last element in the array.

You can even do it in one expression. InputString.Split(" “c)(InputString.Split(” "c).Length -1).ToString

1 Like

what you need from this input
19764/01 32.24 or 32.24 for line 1
20.493 393.190 or 393.190 for line 2

Excelent!!!. Now it’s OK.

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