Two Array in a string i.e. System.String[][]

Hi there,
Need help in getting the output as
ABC,Lim
Sammy,Tan
which is FirstName(0)+“,”+LastName(0) and next new line as FirstName(1)+“,”+LastName(1)
But i need the counter to be dynamic cos it can be more than 2

two variables
FirstName = {“ABC”,“Sammy”}
LastName = {“Lim”,“Tan”}
Output variable type is String
What should the flow and syntax?

Thank you

@YangYang

Please try this

  1. Use for loop on firstname and change the type argument to string
  2. Assign a variable to index in for loop properties
  3. Use inside loop to get as you need currentItem + "," + lastname(indexvar)

And not sure why you need string array of array…

Cheers

Hi @YangYang ,

Assuming you have Equal number of String items in both of the arrays and they are to be matched 1:1, then we can use the below Expression :

Output = (From i in Enumerable.Range(0,FirstName.Count) Select FirstName(i)+","+LastName(i)).ToArray

The above Expression results in an Array of String type, so you have to change the Output variable type also to the same.

Also, Maybe try renaming variables FirstName to FirstNamesList, just so it is marking it as a list.

Hi

Hope the below steps would help you resolve this

  1. Use a For each activity and pass FirstName as input variable and change the type argument as String

  2. Inside the loop use a ADD TO COLLECTION or APPEND ITEM TO COLLECTION activity where in collection mention the output variable name and item property mention as
    item.ToString+”,”+LastName(Array.IndexOf(FirstName, item.ToString)).ToString+Environment.NewLine

  3. This will combine those two names with NewLine before to the next full name

  4. Make sure the output variable mentioned in the activity is of type like this
    System.Collections.Generic.List
    You can browse this type in browse type in variable panel

You can convert this anytime to array by just mentioning like this assign activity

Arrayvariable = listvariable.ToArray()

Cheers @YangYang

Hi Palaniyappan,

i would like to have the output as
ABC Lim
Sammy Tan

1 Like

Hi Arpan,

Didn’t fetch the result i want.
kindly advise what went wrong

Fine

If you would like to print inside the for each activity itself with a writeline then skip ADD TO COLLECTION activity and just mention like this in a assign activity

str_output = item.ToString+”,”+LastName(Array.IndexOf(FirstName, item.ToString)).ToString

Where str_output is a string variable defined in variable panel with default value as string.Empty

Then use a writeline activity next to this assign and mention as str_output.ToString

This can be mentioned even outside the for each loop and u get the same output with each full name one below the another
But for that the assign activity inside the for each loop should be like this

str_output = item.ToString+”,”+LastName(Array.IndexOf(FirstName, item.ToString)).ToString Environment.NewLine+str_output**

If you want to have it as a list output variable Then use this assign and writeline activity next to add to collection activity inside the loop

Cheers @YangYang

1 Like

Thank You Palaniyappan
Got it.

1 Like

@YangYang ,

To print the values, You would have to use a String Join operation in the write line activity like below:

String.Join(Environment.NewLine,Output)
1 Like

Hi Arpan,

It works perfectly.
Thanks alot.

1 Like

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