I’m looking for a way to convert a string, with spaces as delimiters, into a data table that has 10 columns.
Another problem with that is that there are bunch of spaces between each item.
Is it fixed width in that each column text begins at the same position?
No, most of them are, but some columns have numbers. If it is aa shorter number, then there are more spaces, and the other way around.
You can pull them apart using the split function and build your data row:
- Read text into TableName
- For Each Row in TableName
- Assign NewDataRow = TableName.NewRow
- Assign NewDataRow(0) = Trim(String.Split(" "c)(0).ToStrnig)
- Assigned NewDataRow(1) = Trim(String.Split(" "c)(1).ToString) and so on…
Finally, Use Add Data Row activity (set Data Row as NewDataRow and table = TableName)
Does that make sense?
Thanks for the replies, I’ll try it out in a sec.
No problem. This assumes none of the data has spaces in it. If it does, you would need to try and identify a number of spaces that separate them as a delimiter instead. For instance, String.Split(" ",c) would make 5 spaces be your delimiter. The trim removes any additional spaces.
For some reason, UiPath is removing my 5 spaces above and making it appear as just one. I meant for it to show 5 spaces in between the quotes.
Ok, something doesn’t work out for me so I’ll check if I understood you correctly.
I have a 1 dimentional string - 1 line that looks something like this:
ababab ababbababba ababbabababababba aabbababab abbababba.
First I have to split it. I do it like this: Assign string_dt_array = Split(string_dt,“ ”)
Then read text into the dtable. I don’t get this part.
what does it mean to read text into it?
Have you tried to use the “Generate Data Table” Activity?
If you know the Columns in advance, I would recommend specifying the ColumnSizes properties.
For your extra spaces, are you sure those aren’t “tabs” (see below)?
If not, you could replace “more than one space” by “One space”. You can do it with the Replace Activity with the Pattern “\s+” ==> “”
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.