I am using a csv file to hold global variables and constants for an automation project. I know it’s common to use the 3 worksheet config.xlxs (see: How to use a Config file in UiPath - Tutorial - YouTube), but I think it’s easier to use a csv.
My config file is named config.txt and looks like this:
I’ve been running some tests:
- Use Read CSV and and do all get/set operations on the config file using data table activites, or
- Use Read Text File and do all get/set operations on the config file using string handling activities.
Right now I’m testing option #2. Using string handling I can find and return existing values in the config file. There is currently 1 snag. When I use Read Text File to get the config file into a UIPath string, it looks like this:
This is not a huge problem since I can test the config file string with string.contains(“something”) instead of string = “something”, but could someone please answer 2 questions?
- Why is UIPath putting an @ symbol into the Read Text File output string?
- If you look at the first line of the file you can see a squiggle under the ‘y’ of ‘yadayada’. When you mouse hover over the squiggle there’s a popup that says “End of statement expected.”
I thank you, Mesdames et Messieurs, for your kindly informification.
The @ character is indicating that the string is not escaped etc and it is not part of the string
@ppr - I appreciate but do not understand your response.
- I’m not sure what you mean by “the string is not escaped”.
- As to whether the @ symbol is part of the string: when I use write line on the string, the @ symbol does not get written to the console. When I parse the environment line using Text to Left/Right,
Text to left = “environment”
Text to right sometimes = “test” and sometimes = @test"
When I run a string test on the Text to Right string.contains(“test”) succeeds but string = “test” fails.
for example we do have following text file (1 of many ways to test/replicate)
And we do read in the text file into a string:
@ is not part of the string content, as you can see below:
Please read this:
Verbatim strings in C# - Use of @ symbol in string literals (c-sharpcorner.com)
It is basically an indicator used to treat the string litterally, and not interprid potential escape characters such as the
/. So the @ character is not part of your string, therefor it is not displayed when using writeline.
As for your usage of a txt file for storing these type of name/value pairs… I can understand the appeal of staying away from an excel config, and it surely can have its advantages in certain cases, but I’d definately go for the
read csv activity. Using a for each row on the content makes it so much easier to create a config dictionary over reading an entire tex file and using string manipulation to try and get the same end result.
Stick to what works
@ppr and @Jeroen - thank you for taking the time to respond.
- Change the value of environment to “production”.
- Use the Matches activity and the Text To Left/Right activities to find and parse the line “environment,production”.
- Set up a couple of if statements:
The “if contains” is successful. The “if equals” fails. There are no extraneous spaces anywhere that I can find.
Whoops. I just realized that I forgot to return the 2nd if statement to use
but I’ve changed it and the “equals” still fails.
Also, @Jeroen - I partly abondoned the Read CSV / Data Table approach. It was so frustrating that you must use the Lookup Data Table to find a matched RowIndex, but Lookup Data Table does not return a row object, which activities like Update Row Item require as an input! It is so frustrating that there does not seem to be an easy way to convert a row index to a row object. I’m sure you can do this in VB/Invoke code, but I am not able to get Invoke Code to ever work. (See: Invoke Code Always Fails: Method Not Found - Help / Activities - UiPath Community Forum
it is not really clear what you want to show/replicate. Maybe you can do it more simple within the immediate panel.
About the following, maybe you can show us the screenshots along with the configured properties of your implementation: