Please suggest me here,
Need to convert array string into datatable.
below given array of string:
{“Ani: xyz: hat:”, “yes yes yes”, “Joe lay 12hg hhh”,“abc bbb”}
consider 1st row as column headings (Ani: xyz: hat:)
Thanks&Regards
soundarya
Please suggest me here,
Need to convert array string into datatable.
below given array of string:
{“Ani: xyz: hat:”, “yes yes yes”, “Joe lay 12hg hhh”,“abc bbb”}
consider 1st row as column headings (Ani: xyz: hat:)
Thanks&Regards
soundarya
Dim arr_columns As String()
arr_columns=arr_Forumvalues.take(1).ToArray.first.split(“:”).toarray
For Each r In arr_columns
dt1.Columns.add(r)
Next
dt1.columns.add(“Column4”)
For Each r In arr_Forumvalues.skip(1).ToArray
arr_datarow=r.Split(" ".ToCharArray).ToArray
dt1.Rows.Add(arr_datarow)
Next
try this using invoke
if you want first column as header you need to add a Extra column,Because the Values in the 3 place of input are 4
Thats why i have added One more column named as Column4
Hi @Soundarya_Guduri1,
Try using Generate datatable from Text activity. You can use [colon][space] as column separators and [comma] as Newline separator.
Please mark this as the solution if it helps you.
Regards,
Hi @Soundarya_Guduri1 ,
From the initial analysis, we can understand that there are 3 columns considering space as the separator but for the 2nd row, there are 4 words, so it would not fit or we do not know the condition on how to fit these values into the respective columns.
Maybe also provide an Expected Output and also with a varying sample so that we can confirm what is the logic behind assigning the values to the respective columns.
Please find the below linq query
syntax : ArrStr.Select(Function(a) DT1.LoadDataRow({a},False)).copytodatatable
Cheers!
Thanks for your response can you share me the xaml please
Thankyou for your response
I have tried
The result is shown below
Values got extracted but the values need to split among cells
Regards
soundarya
Hi @supermanPunch
The output should look like
regards
soundarya
Hi @Shiva_Nikhil your code is about to solve the issue but how to write invoke code for given array of string.
Can you please try for this type of array of string
{“Ani: xyz: hat:”,
“yes yes yes”,
“Joe lay 12hg hhh”,
“abc bbb”}
I have just modified the code so that you dont need to add extra column
Dim arr_columns As String()
arr_columns=arr_Forumvalues.take(1).ToArray.first.split(“:”).toarray
For Each r In arr_columns
dt1.Columns.add(r)
Next
For Each r In arr_Forumvalues.skip(1).ToArray
arr_datarow=r.Split(" “.ToCharArray).ToArray
dt1.Rows.Add(arr_datarow(0).ToString,arr_datarow(1).ToString,string.Join(” ",arr_datarow.skip(2).ToArray))
Next
i Have tested with your input array, getting the same output for me which mentioned above
I am sharing my xaml here please have a look here.
Sequence2.xaml (8.6 KB)
the input array format is in this xaml
Regards
soundarya
Please check the below image
Array of array of string = your array.Select(Function(a) a.ToString.Split({":“c,” "c},StringSplitOptions.RemoveEmptyEntries)).toarray
Converting array of array inito datatable
datatable = Array of array of sting.select(function (a) dt1.rows.add(a)).copytodatatable
Cheers!
please share the xaml
refer the below xaml
arraytodatatableForum.zip (5.0 KB)
Dim arr_columns As String()
arr_columns=arr_forumvalues(0).split(“:”).ToArray.where(Function(a) Not String.IsNullOrEmpty(a)).ToArray
For Each r In arr_columns
dt1.Columns.add(r.Trim)
Next
For Each r In arr_Forumvalues.skip(1).ToArray
arr_datarow=r.Split(" “.ToCharArray).ToArray.where(Function(x) not string.IsNullOrEmpty(x)).toarray
dt1.Rows.Add(arr_datarow(0).ToString.Trim,arr_datarow(1).ToString.Trim,String.Join(” ",arr_datarow.skip(2).ToArray).ToString.Trim)
Next
Thankyou for your solution
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.