Convert arraylist to string

Cna some pelase help me on How to print Values in Array variable as string.
As I created an Array varaible and it is storing the values as a list and I wanted to print those values.

1 Like

@sambana_karunakar

string.join(“,”,ArrayVariable)
This will prient all the elements of your array seperated by comma

Regards,
Mahesh

5 Likes

@MAHESH1 I need like one by one list not in same line, how to do that

@sambana_karunakar

string.Join(Environment.NewLine,Array_Variable)

Regards,
Mahesh

4 Likes

@MAHESH1 Sorry some thing is missed not getting expcted results. let me tell you,
I have an CSV file and in with 2ncloumn has many and only few row are has data remaining are empty. and I need the non empty cell vaules to store in a Array varaible and I wanted to print the those stored values in a mail body. this is my requirement

please check and help me at print all values in one mail as of now gettiing each values in each mails let say if there are five cells has data it is sending five mails. i need five values to print in one mail. if put the outlook activity outside of the for each loop it is sending only one mail with printing last cell value.(like fifth value out of five).

@sambana_karunakar
What is the datatype of list you are using

Regards,
Mahesh

list is string

@sambana_karunakar

Create a Variable of ListOf Strings List_Names
Use Add to Collections Activity
Add row(“Column-1”).ToString to collections i.e List_Names

At last outside for each
strA=string.Join(Environment.NewLine,List_Names)

Regards,
Mahesh

@sambana_karunakar
If its a string then definitely it will contain only the last value.

Regards,
Mahesh

Hi @sambana_karunakar,

First get the column value for. The datatable to array.(use linq to get the column value to array)
@MAHESH1 try linq query to get all the value

Then use
string.Join(Environment.NewLine,Array_Variable)

If you use for each Loop each time you will get mail with single value

Regards,
Arivu

@sambana_karunakar
Let us take you are having a datatable dta
No need to use foreach row
List A-List of Strings-Use in Assign Activity

ListA=(From p in dta.Select()
where not string.IsEmpty(Convert.ToString(p.Item(“Column-1”)))
Select Convert.ToString(p.Item(“Column-1”))).ToList()

string a=string.join(Environment.NewLine,ListA)

Regards,
Mahesh

2 Likes

Good work @MAHESH1,

@sambana_karunakar use this code

Small change

string a=string.join(Environment.NewLine,ListA.ToArray())

Pass this string value to mail and send it

Regards,
Arivu

1 Like

@arivu96
I think even if its list also it will join.

Regards,
Mahesh

Yes correct. I did’t noticed. :slight_smile:

@arivu96

No problem :grinning:

Regards,
Mahesh

Hey I am getting error inthis can you correct it again

(From p in dt.Select()
where not string.IsEmpty(Convert.ToString(p.Item(“Column-1”))
Select Convert.ToString(p.Item(“Column-1”))).ToList()

@sambana_karunakar
Replace dt with your datatable variable

Regards,
Mahesh

dt is my data varaible

@sambana_karunakar
Can you share the screen shot of error
Regards
Mahesh

please chcek