# Column Expression node error? string length

**URL:** <https://forum.knime.com/t/column-expression-node-error-string-length/46143>\
**Category:** KNIME Analytics Platform\
**Tags:** bug, node\
**Created:** [August 19, 2022, 4:45pm UTC](https://forum.knime.com/t/column-expression-node-error-string-length/46143 "2022-08-19T16:45:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![FrankColumbo](https://forum-cdn.knime.com/user_avatar/forum.knime.com/frankcolumbo/32/37170_2.png) [@FrankColumbo](https://forum.knime.com/u/FrankColumbo)\
**Post date:** [August 19, 2022, 4:45pm UTC](https://forum.knime.com/t/column-expression-node-error-string-length/46143/1 "2022-08-19T16:45:32Z")

</div>

Hello

I have come across something odd and inconsistent with the column expression node.

I am aware this might be a user bug and not a KNIME bug 😉

I have created a example workflow, for those who wish too, to download.

> **[column expression node error – frankcolumbo](https://hub.knime.com/frankcolumbo/spaces/Public/latest/column%20expression%20node%20error~bKHxL8i_O-gE8TrF)**
>
> Solutions for data science: find workflows, nodes and components, and collaborate in spaces.

Objective: get a list of strings of varying length. make each string 10 characters long by either chopping the 11th character to the nth, or filling the start of the string with X(s).

Nodes:  
Table creator holds the list of strings  
Column Expression Node 6: removes spaces  
Column Expression Node 9: adds a column called value AND counts the length of string.  
**Question 1** : why must I reduce the length of string by 1 to get the correct length? (In some languages I would expect to add 1 to the length because the first count is 0, but I have never had to reduce it by 1 before)  
Column Expression Node 10: removes 11th character to the nth OR fills the start of the string with X(s)  
Column Expression Node 11: counts the length of string.  
See Question 1  
**Question 2** If you look at the output table of node 11 you will find lengths of either 9 or 10 even though there are 10 characters in each string. How? Why?

example row 6: value = AjaxAmster len = 9 (there are 10 characters in AjaxAmster)  
example row 108: value = FCBarcelon, len = 9 (there are 10 characters in FCBarcelon)  
example row 5: value = XXXXASRoma, len = 10 (there are 10 characters in XXXXASRoma)

Just one more thing…

This was cobbled together to show an example of what I have found, I know the code within the column expression nodes are not ideal.

Frank Columbo

---

<div class="post-metadata">

**Author:** ![ArjenEX](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/97f17d/32.png) [@ArjenEX](https://forum.knime.com/u/ArjenEX)\
**Post date:** [August 19, 2022, 5:25pm UTC](https://forum.knime.com/t/column-expression-node-error-string-length/46143/2 "2022-08-19T17:25:26Z")

</div>

Hi @FrankColumbo

The issue here is related to hidden “junk” characters in your input. At face value, the strings look clean but there is something hidden in it.

Instead of just replacing the space, I opt for a Regex to remove anything that is not equal to a letter by the means of `regexReplace(column("team"),"[^a-zA-Z]" ,"" )`

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/3/2/3291a39120d6f95d5a2cd5daf68c3e68516d3e0f.png)  
Note: Expand the Regex with characters like a dash or 0-9 if you know those are within the list football clubs.

If I then run `length(column("team"))` , the Column Expression return the correct length.

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/9/c/9c9ab166ea987a302d41914f86647b27cf395011.png)

Although it’s cobbled, for the sake of it depending on if you know the function: you can shortcut _node10_ by using

```auto
if (column("len") <= 10) {
    padLeft(column("team"),10,"X" )
} else {
    left(column("team"), 10)
}

```

It saves you a bunch of coding.

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/c/a/ca148c2a41567b52929b3acc7ceaa79be73fe858.png)

That will get you your equalized string of length 10.

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/d/9/d92b54f4b555c1d7b5d32077be698e65f1ee57ed.png)

See WF:  
[column expression string length operation.knwf](https://forum.knime.com/uploads/short-url/6KvLVHhxLkpV0XUKi6Jobi09qb3.knwf) (63.1 KB)

Hope this helps!

---

<div class="post-metadata">

**Author:** ![FrankColumbo](https://forum-cdn.knime.com/user_avatar/forum.knime.com/frankcolumbo/32/37170_2.png) [@FrankColumbo](https://forum.knime.com/u/FrankColumbo)\
**Post date:** [August 19, 2022, 5:46pm UTC](https://forum.knime.com/t/column-expression-node-error-string-length/46143/3 "2022-08-19T17:46:27Z")

</div>

amazing, awesome, thank you!

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [August 26, 2022, 5:46pm UTC](https://forum.knime.com/t/column-expression-node-error-string-length/46143/4 "2022-08-26T17:46:39Z")

</div>

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