Join multiple index in an array to form a new variable

Example of my string array looks like this:
Serialno. firstname middlename lastname IDnumber Country Date

I have split the array by spacing, so i count from the back to extract each individual index (starting from date, country, IDnumber).
From my example, ID number is index 4. How do I write my formula "If Index 4 is ID number, then join Index 1 2 3 (firstname middlename lastname) to create a variable Name?

Hi,

How about the following?

Name = String.Join(" ",yourStringArray.Skip(1).Take(3))

Regards,

Thanks!
Currently, I am stucked at finding the Index of IDnumber which can vary. I have saved it as a variable name: ID
Then after,
If index is 3 means [0], [1], [2]. Join to become Name.
If index is 4 means the [0], [1], [2], [3]. Join to become Name.

How should i write the above script?

Hi,

Is there any rule for ID number such as 9digits numeric etc?

Regards,

Hi, its alphanumeric, varies in length (7/8/9 alphanumeric)

HI,

Is there any way to identify whether ID number or LastName?
For example Id number always starts number or lower case letter etc…

Regards,

Hi,

If the string always has Country and Date after ID number and they don’t have any whitespace , the following might work.

arrString = yourString.Split(" "c)
resultString = String.Join(" ",arrString.Take(arrString.Length-3))

Regards,

My data is reading business company information, in particularly search for the line which contains different directors’ details.

So the line I retrieve will look like this:
Serialno.(sometimes it appears or not appear) firstname(vary) middlename(vary) lastname(vary) IDnumber(vary) Country(vary) Date(vary)

There is no fixed data for me to identify IDnumber because it can either starts with number or starts with alphabet depends on the person nationality.

String Array:
Serialno. firstname middlename lastname IDnumber Country Date

Split String Array by Spaces
[Serialno.] [firstname] [middlename] [lastname] [IDnumber] [Country] [Date]

I start backwards to locate my variables, for example:
To locate Date: StrArray(StrArray.Count-1), followed by Country, then IDnumber

Hi,

If the above works well, the following also works probably.

resultString = String.Join(" ",arrString.Take(arrString.Length-3))

And i’d like to confirm that if index is 4, we should join [1],[2] and [3], shouldn’t we?

If index is 3 means [0], [1], [2]. Join to become Name.
If index is 4 means the [0], [1], [2], [3]. Join to become Name.

If so, the following might be better.

resultString = String.Join(" ",arrString.skip(arrString.length-6).Take(3))

Regards,

Your suggestions have been very useful! I am able to see some results now. I will go play around with the script given. Thank you so much for your help! :grinning:

1 Like

uh yes correct. because [0] is serial no. I make a typing mistake.

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