Error: The expression contains an invalid string constant

I am using this process to compare two excels. Inside a for each, i have an assign:

dtDefendants.Select(“Defendant = '”+CurrentRow(“Defendants”).ToString.Replace(“’”,”’’”))

When i run this process, it fails with the error: Assign: The expression contains an invalid string constant: 'Admiral Security Services Inc.

('Admiral Security Services Inc. is the name in the cell from the excel). Not sure what this error means or how to fix.

@atarantino

I guess you missed a single quote at the end

dtDefendants.Select("[Defendant] = '"+CurrentRow("Defendants").ToString.Replace("'","''") + "'")

You can as well use like this first check if you are getting any rows

DtDefandants.AsEnumerable.Where(function(x) x("Defendant").ToString.equals(currentrow("Defandants").ToString)).Count>0

And to get values into table

DtDefandants.AsEnumerable.Where(function(x) x("Defendant").ToString.equals(currentrow("Defandants").ToString).CopyToDataTable

You can as well use a filter datatable activity

Cheers

Hi @atarantino Can you please check below link

The expression contains an invalid string constant - Help - UiPath Community Forum

Yes I believe that is what the problem was. I added the + “'”) to the end and it bypasses that error but gives me a new error (on the same assign) for:

Assign: Syntax error: Missing operand after ‘s’ operator.

I think that the results in my excel column are written with an ’

(i.e., Gregory’s Bar)

How do i account for results with an ’ ?

1 Like

@atarantino

You are using a replace already…please check if the single quote you gave is same as you are getting it in the input

.Replace("'","''")

Or if there are any other special characters

cheers

Yes the input is a word that has 's at the end of it. There are no other special characters in the cells in that column.

@atarantino

Yes replace should be taking care…can you show a screenshot of what you used please

Or if you can attach a input file or xaml you ar eusing would help

Cheers

Here is the .xaml

Main.xaml (42.2 KB)

heres a sample of the file i’m running through.

test.xlsx (12.0 KB)

@atarantino

When I Open I see this error…may be you copy pasted the replace…please remove the double quotes and single quotes and retype them again in the editor of UiPath

I just tested the same formula on your file and it threw no error once I replaced those inverted comma

cheers

dtDefendants.Select(“Defendant = '” + CurrentRow(“Defendants”).ToString.Replace(“'”, “‘’”) + “'”)

Perfect - thank you.

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