Help with String Manipulation/Split function - check if the word/variable is present on every row in each .txt file

I need to read 2 .txt files containing some json objects/records. The content of the first .txt file is as below:

{“Id”:“128-c7f5-4fb9-b1d7-891bced4”}
{“Id”:“3f2d-203c-4501-8308-97b0”}
{“Id”:“9c-5b4b-47d7-a963-a4983c17”}
{“Id”:“fe70a472-65cb-4411-b958-440adc”}
{“Id”:“c1c8e-f68f-439c-9db0-ce0ce3ea”}

the content of the second .txt file is:
{“Id”:“128-c7f5-4fb9-b1d7-891bced4”}:GO
{“Id”:“3f2d-203c-4501-8308-97b0”}:GO
{“Id”:“9c-5b4b-47d7-a963-a4983c17”}:GO
{“Id”:“fe70a472-65cb-4411-b958-440adc”}:GO
{“Id”:“c1c8e-f68f-439c-9db0-ce0ce3ea”}:GO

Once they are read, I want to check if the word/variable “Id” is present on every row in each .txt file. If yes, I want to return a Boolean True, otherwise return a False.

This is will be in different workflows so hopefully I get one solution for each ( I suppose they will be similar(

I have looked at similar issues in the past but did not help.

Help will be appreciated.

  1. Read Text File: First, use Read Text File activities to read the data from both of your .txt files. Output each of them to a string variable. Let’s say textData1 and textData2.
  2. Generate Data Tables: The action will return the entire text data from each .txt file. Now we want to separate this into lines/rows. We can do this by using Generate Data Table activity and outputting to datatable variables, say dataTable1 and dataTable2. Use NewLine as Column separators in the properties of the activity.
  3. For Each Row: Use two For Each Row activities (one for dataTable1 and another for dataTable2). In each of these, use an If condition. In the condition field, use row(0).ToString.Contains("""Id""") and if the condition is false, Output a Boolean Variable as False and break the loop.
  4. After the For Each Row activity, If no row is missing the “Id”, your Boolean will remain at its default value of True.

Note: row(0) is used because the first column will contain each line from your text file. Adjust if more columns are present in your scenario.

1 Like

We do understand that you are interested on which id is not present in both

We can do it different on string level

Assign Activity
arrLines1 | String Array =
File.ReadAllLines(PAthtoFile1)

Assign Activity
arrLines2 | String Array =
File.ReadAllLines(PAthtoFile2)

Assign Activity
arrCommon | String Array
arrLines1.Intersect(arrLines2).toArray

Assign Activity
arrOnly1| String Array
arrLines1.Except(arrCommon ).toArray

Assign Activity
arrOnly2| String Array
arrLines2.Except(arrCommon ).toArray

@ppr looking at :

Assign Activity
arrCommon | String Array
arrLines1.Intersect(arrLines2).toArray

it seems you assume these files have something to do with each other.
These are two different workflows, I just lumped the questions into one.
Could you provide a solution/suggestion for just one?

image

Results:

image

Maybe the following helps for the start

For each Activity | item in File.ReadAllLines(PAthtoFile) | (Older versions: TypeArgument: String)

  • IF Activity | Condition: item.ToUpper().Contains(“ID”)
    • Then: Log Message: “ID is present”
    • Else: Log Message: “ID is not present”

Also have a look at this alternate:

arrResult | StringArray =

File.ReadAllLines(PAthtoFile).Select(Function (x) x & ": " & x.ToUpper().Contains("ID").toString).toArray

Assign Activity:
hasAllWithID | DataType: Boolean =

File.ReadAllLines(PAthtoFile).All(Function (x) x.ToUpper().Contains("ID"))

@marian.platonov @ppr
FormatStringInTextFile.zip (5.4 KB)

Attached is my workflow. It should be returning a TRUE because “id” was found in the file, but its returning a false instead. I suspect this behavior is because I couldnt figure out how to Use NewLine as Column separators in the properties the generate Data Table of the activity.
Kindly help! Thanks

I fixed the problem, thanks @marian.platonov and @ppr

Is because of the “Id” double quotes characters → should be "Id" in the txt files.

You can perform a replace for and to ".

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.