How to extract from array

Hi,

I’ve got some troubles deleting data from an array.
I’m reading PDFs line by line and I have several info in one line like for example:

COD365 16/03/2020 Hanna 08/04/2020 2 6 IT 368 6 12345678

i’m taking some parts with splits, some parts with matches and while im taing info i’m erasing from the line de info that i’ve take with a replace like → line.replace(value,“”)

THE PROBLEM:
when I get the “6” number is obviously taking all the “6” in the line so it’s making a mess:
COD365 16/03/2020 Hanna 08/04/2020 2 6

I want to know if there is a way to extract .last froman array. Extract, put it out of the array.

Let me know if you find something.
Greetings

I’m not sure, what you are trying to achieve here? If it’s just taking the last element from an array you can use the following snippet

LineArray(LineArray.Length-1)

Hi @Praveen_Erakkingal thank you. You can do also LineArray.Last and it will give you the last item. But I want to delete this item from the array that i’ve made with this line and i want to kow if exists a code way to do it.

LEt me make a more easy example
I have a line with this numbers:
line = “1 3 6 5 6 7 6”
I want to disappear the last number from this without deleting the other “6”
So line.replace(“6”,“”) doesn’t work
line.replace(split(line," ").last) doesn’t work
if I use substring idetify the last as a “6” so it will take the first 6 that it sees so it cannot work either

The thing that i’m doing now is a “for each” of split(line," ") identifying the index and put the values in another string but if the index is the last one simply dont put the value on the new string, that way I’ve fund a solution but i want to see if i can do this into a simple code

Thank you

If you just want to remove the last 6 (with space), you can use this
line.Remove(line.LastIndexOf(" 6"),2)

2 Likes

@KevinDS If you just want to remove the Last Element in the Array considering it can be anything, then you can try this :
arrayOfStringVar = line.Split().Take(employeeNames.Count-1)

I have assumed line is a String varaible where elements are separated by space as the Example shown.
Here the Take method leaves out the Last Element by considering only elements upto Last but one.

Hope this is what you needed.

3 Likes