How to convert string to array list

activities

#1

Hi,
I have a string with list of names extracted from get text, now how can i convert into array list separated by “,” so that i can use these list in loop.

Ex:
Mahesh
Ramesh
Suresh

Result: {Mahesh,Ramesh,Suresh}

Thanks


#2

Hi @balu,

Use environment.newline split the string.

Try below code
arrvalue=strValue.Split(Environment.NewLine.ToArray, StringSplitOptions.RemoveEmptyEntries)

Regards,
Arivu


#3

getting result as system.string[].


#4

Yes array of string,

So u don’t want array of String u just want the format like string only??


#5

i have created a array variable with system.string[]

input:
red
white
yellow

expected Output:
{red,white,yellow}

but its giving output as system.string[]


#6

Hi @balu,

strValue=strValue.Replace(Environment.NewLine,",")

Yes split option will return the array of String value only.

Regards,
Arivu


#7

Please find the solution here

Main.xaml (6.9 KB)


#8

Hi arivu,

Let say i have StrVaribale with list of names

red
yellow
white

can i read each row from variable to loop in further.


#9

Hi @balu,

Use this code to get the value. And use for each to loop through the value.

Regards,
Arivu


#10

this is the output “system.string[]” after using above code think its not getting the values.
out put is not accurate.


#11

Hi,

i think the issue here is that you are trying to view the output the wrong way as it is a collection. arrvalue.ToString will show as System.String[]. If you loop through arrvalue and check each item it should show correct output. Or you can just check for example arrvalue.First, which will give the first item in your array.

br,
Topi


#12

yes bro correct. i tried to view array value so gave system.string[] value when i use it in loop i got exact values. thanks @arivu96 & @Topi.


#13

hi @arivu96,

for above same example how can we get count of all names?

Thanks.


#14

Hi @balu,

arrvalue.length

Regards,
Arivu


#15

Hi its not removing empty strings.?
How to remove empty values from these array ??


#16

Hi Balu,

Sometimes logical thinking gives the solution for technical issues.
User Replace String Activity to remove the spaces in String and Array of string below image may give the solution for your issue.


#17

HI @balu,

For example myColors is your array try below code.

List<string> tempListColors = new List<string>();
foreach (string color in myColors)
{
if (!string.IsNullOrEmpty(color))
tempListColors.Add(color);
}
myColors = tempListColors.ToArray();

Regards,
Arivu