How to declare String array and assign value in array in for each loop

I am unable to assigning value in string array in for-each loop.

3 Likes

@pankajs3,

You need to pass the index and value to the string array,

image

4 Likes

Hi @pankajs3

  1. Use assignactivity and declare array of string.

  1. Then assign value to the variable {“First”,“Name”,“Last”}

3.Use For Each Activity.

image

Hope this might be helpful to you.

cheers :smiley:

Happy learning :smiley:

4 Likes

i want to assign value dynamically in string array in for-each loop. While assigining value i am getting error:

system nullreferenceexception object reference not set to an instance of an object uipath

2 Likes

First solution will work @pankajs3 , try and let me know if you get the same, make sure the ArrayString is a string array type variable

2 Likes

yes am doing same way as you mentioned in first solution but getting error which i mention in my previous reply.

2 Likes

If you have null values in the DB, it won’t accept. So, give a if condition above the assign and skip the values if the values are null… Check that by using a message box @pankajs3

2 Likes

@HareeshMR Can you tell me how to declare and initialize the String array in uipath

2 Likes

In the variables pane, click on new variable and give a name. Then in the type, click thrice . you will get a drop down as show and select Array of [T]

image

Then select String in that

image

just like mate @pattyricarte mentioned above

2 Likes

@HareeshMR ow to initialize array of string, before adding any number of elements in String array in for-each loop

2 Likes

Come again @pankajs3,

I dont understand

1 Like

@HareeshMR
Which above part you mentioned is declared part, but how to initialize an Array.
“arrayString String” is declared part, How to initialized it.

1 Like

Ohh, I forgot that @pankajs3

Here it is : StringArray = new string(){}

1 Like

Thanks @HareeshMR
Can we add any number of element with this initializing

1 Like

Yes @pankajs3,

Here is the sample workflow to enter the values into a string array from data table.
DataTablesAndExcel.xaml (10.7 KB)

First of all, we are declaring and initializing a array with the particular length with the number of rows in a datatable and then we are adding the data to the array based on the index :slight_smile:

Hope this helps and let me know if you have any doubts

3 Likes

That’s i was looking for.
Thanks @HareeshMR

Glad to help @pankajs3

@HareeshMR
i don’t know, How to close the topic?

@pankajs3,

Just marking the best answer you find as useful

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