Getting index of an Array from a word

Hi, I’ve a text file that has data with some numbers in between. I’m splitting the data based on newline and now I need to search a number which I would have in a data item and get the index of that row in the array.
For instance I’m searching for “124578” it might have something like 0000124578 some random text
Input.txt (2.2 KB)

Note: We might have any random text in the line before and after the number

@Babjee.Vangipurapu
Welcome to the forum

Your sample text has no line breaks so:

will not have any splits

However we could use regex and retrieving the position e.g. like:
grafik

And can also exctend it to multiple matches if needed
[CheatSheet] - System.Text.RegularExpressions | RegEx - News / Tutorials - UiPath Community Forum

Hey @Babjee.Vangipurapu

You can use a assign activity:

arr_Output = str_Input.Split(" "c).Where(Function(x) x.IsNumeric).ToArray

You will get all the Numbers present in the string in a Array of String variable!

Need more assistance then let me know!

Image for your reference:

Note: str_Input = "Your Input Text...!"

Regards,
Ajay Mishra

Hi @ppr ,

I don’t want the index of the number in the complete string. I need to split the text, after splitting the text I want to get the row index in which row the values exists.

Hey @Babjee.Vangipurapu

Is this helpful to you?

You can see in above screenshot array of all the numbers in string.
If Yes, then send the input excel file for comparing!

Regards,
Ajay Mishra

Hi Ajay,

I’ll split based on newline, then I’ll get the string instead of numbers separately. Attaching the screenshot after splitting text.

From this array I need the index of the line which contains the search value. For example if I search for 879512 I need to get my output as 2 since index starts from 0 and the value879512 is on 3rd Index off array.

we told also

so elaborate more on how you have split

Okay @Babjee.Vangipurapu Thanks for the clarification!

Use this in assign:

int_Index = Array.IndexOf(str_Input.Split("."c).ToArray,str_Input.Split("."c).ToArray().Where(Function(x) x.ToString.Contains("879512")).ToArray().FirstOrDefault)

You can change or use a variable Contains(“879512”)).ToArray() here in place of “digits” for any number you want to find!

Got the expected output!

Screenshot for your reference:

Regards,
Ajay Mishra

1 Like

Thanks @Ajay_Mishra I’m now getting the desired result

1 Like

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