Apply length function in string manipulation

Hello,

I need to do a substr and I have differents length in the specific column, so i need to apply the length function to firstly filter by length. I triyed this expression:

image

The error indicates a type conflict, but both columns are string:

image

Any ideas how to solve this?
Thanks.

Hi @jpages,

Re your specific question, this error occurs when it cannot determine the type of your expression, or needs to perform a type conversion.

You can usually resolve this by wrapping the entire expression in the string() function

e.g

string( --your statement-- )

I was trying to work out your actual statement though as it looks a little odd. Without being able to see your data I cannot see what it is that you are trying to do as the construct you are using doesn’t make sense to me at the moment.

2 Likes

Thanks for the reply.
I was trying to apply:

substr($coordinates$, 20, 12)

to register where length of $coordinates$ are equal to 33 characters.

Which thinks is the best option to accomplish that?

Hi @jpages , I found a couple of things that are weird from your screenshot.

  1. You mentioned 2 columns, and you showed “coordinates” and “length” as columns, both string.
    Are you using the “length” column? What does that column represent? Is it different from the results from the function length($coordinates$)? How is that column being used here? If it’s the same results, how is that column created (it should be an int if it’s the length of $coordinates$)?

  2. I’m guessing you are using the String Manipulation? You can’t really do any if conditions in the String Manipulation. For that, you need Column Expressions node instead, that would be your best option. So that “syntax” that you are trying is not working as you expected.

For the Column Expressions, you can use this:

if(length(column("coordinates")) == 33) {
    substr(column("coordinates"), 20, 12)
} else {
    column("coordinates")
}

Note: substr($coordinates$, 20, 12) (or substr(column("coordinates"), 20, 12)) will give you characters from the 21st position up to 32nd position, so you are not taking the last character, if that is what you want.

6 Likes

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