String.startswith() not founding right value

Hi!
So I have the code bellow to retrieve data from a DataTable and compare it with a variable called filename (which it’s returning the filename inside a for each )

My issue here is, the string.starswith() function it’s not entering on the If statement when it matches the row on the DataTable

My If condition: filename.Split("."c)(0).ToString.Trim.StartsWith(“DTFiles.rows(counter)(0).ToString”) = true

I’ve tried to do the if statement without the split() function (which it’s only removing the extension) but it’s the same.

image

Use the trim in at both the places to make sure there is no space…and check

1 Like

At first get file name with this:

image

filename = System.IO.Path.GetFileNameWithoutExtension(filename)

In this scenario you don’t need split.

1 Like

When I try to output it, it throws an error on message box: Object reference not set to an instance of an object.

It’s the same :confused:

Try to add Write lines/ Message Box with:
filename
DTFiles.rows(counter)(0).ToString
before IF Statement
and chceck values

You can also set Breakpoint in If statement and check variables and values in ‘Locals’:

1 Like

Yea, the error I told you about it’s on the message box before the if (the one that’s on the post)

What values do you want to display in the message box?
Give some flow screenshots.

You did both side like below?

you have passed the “DTFiles.rows(counter)(0).ToString" value as string…
Remove double quote from here

It should be like below

filename.Split("."c)(0).ToString.Trim.StartsWith(DTFiles.rows(counter)(0).ToString.Trim) = true

1 Like

Yeah, @Pravin_Patil1 good tip for @cteixeira. @cteixeira look what I’ve made on my screenshoots:

image

Nvm it’s working! haha
I just needed to change the filename assign you give me to system.IO.Path.GetFileNameWithoutExtension(file.ToString).ToString
Thank you! :slight_smile: Now I need to find a way to skip the row when it doesn’t find any file after running through every file

That actually helped a lot!! Wow… what trouble can a double quote do! hahaha
Thanks a lot! :slight_smile:

Welcome :slight_smile:

It happens a lot and take more time than complex issue to get eyes on…

1 Like

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