Hello! I have a text file that I need to read, line by line, and extract the values based on a colon (“:”) delimiter. The file is structured in the following way:
I am trying to automate the provisioning process for an application in my company, so I need to be able to extract these values and enter them into a form. If I can simply extract the values themselves, then that will be sufficient. However, I’d prefer to have them assigned to variables named after the category. This would make it more intuitive to work into the rest of my workflow.
@ibarnes
As it is dynamic you can not do on runtime as variables have to be defined before compiling. But you can use a dictionary (Of String, String) and fill it up dynamicly on runtime with dictVar(“Category_X”) = Value_X
1.) Create a variable MyLineArr of type String Array.
2.) If MyText is the text you’ve read from the file, set MyLineArr to MyText.Split("\n"c).
3.) Create a For Eacch loop to iterate over the elements of MyLineArr.
4.) In the For Each loop, if MyLine is an element of MyLineArr, you can get the category from System.Text.RegularExpressions.Regex.Split(MyLine, "\s*:\s*")(0), and the value from System.Text.RegularExpressions.Regex.Split(MyLine, "\s*:\s*")(1).
Okay, I’ve done that, but when I set that variable equal to what you told me to, I get the error: "uipath option strict on disallows implicit conversions from ‘string’ to ‘char’.
Okay, going back to the final step you sent, what do you mean by “if MyLine is an element of MyLineArr”? Should I set “MyLine” equal to one of the two regex statements you sent (for the category and value)?
MyLine is item in your screenshot. I just used MyLine to specify what was being pulled from the array, as item represents a single line in the data you’ve split.
No, you’ll need to assign variables (e.g. Category and Value) to System.Text.RegularExpressions.Regex.Split(MyLine, “\s*:\s*”)(0) and System.Text.RegularExpressions.Regex.Split(MyLine, “\s*:\s*”)(1).
Alright, I’ve tried this for Category, but I’m getting the “strict on disallows implicit conversions from ‘object’ to ‘string’” error. Here’s what my setup looks like:
Also, since this is a “For Each”, wouldn’t the current Category and Value variables get overwritten by the next iteration when it runs? Ideally, I’d like to end up with a number of different variables (named after the category) whose values are those from the split text.
And yes, they would be overwritten, so you need to handle these variables in this loop however you intend to deal with them, whether processing them at this moment, adding to a dictionary, adding to a datatable, etc.