# String Manipulation, multiple expressions

**URL:** <https://forum.knime.com/t/string-manipulation-multiple-expressions/30346>\
**Category:** KNIME Analytics Platform\
**Tags:** knime-ap\
**Created:** [January 31, 2021, 4:26pm UTC](https://forum.knime.com/t/string-manipulation-multiple-expressions/30346 "2021-01-31T16:26:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gilbert13](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/g/919ad9/32.png) [@Gilbert13](https://forum.knime.com/u/Gilbert13)\
**Post date:** [January 31, 2021, 4:26pm UTC](https://forum.knime.com/t/string-manipulation-multiple-expressions/30346/1 "2021-01-31T16:26:37Z")

</div>

Hi everyone  
i’m new Knime user,  
anyone can suggest me any effective nodes to solves this problem :  
col1  
216520000000004  
216521300000006  
2165277B1000003  
2165212D1000007  
216524200000004  
etc

expected new col  
65200  
65213  
65277B1  
65212D1  
65242

i used to solved this in excel with function  
=IF(OR(MID($A1,8,1)=“B”,MID($A1,8,1)=“D”),MID($A1,3,7),MID($A1,3,5)).

tks

---

<div class="post-metadata">

**Author:** ![elsamuel](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/e/b4bc9f/32.png) [@elsamuel](https://forum.knime.com/u/elsamuel)\
**Post date:** [January 31, 2021, 5:11pm UTC](https://forum.knime.com/t/string-manipulation-multiple-expressions/30346/2 "2021-01-31T17:11:03Z")

</div>

Welcome to the forum, @Gilbert13.

For this, I would use the Column Expressions node. The following expression works if the column name is ColA :

```
if (or(substr(column("ColA"),7,1) == "B"), (substr(column("ColA"),7,1) == "D") )
    {
        substr(column("ColA"),2,7)
    }

else 
    {
    substr(column("ColA"),2,5)
    }

```

It’s basically the same as the Excel formula you have now, but KNIMEified:

- use the _substr_ function instead of _MID_
- account for the fact that character indices start at 0 in KNIME
- adjust format for the column expression node

---

<div class="post-metadata">

**Author:** ![Gilbert13](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/g/919ad9/32.png) [@Gilbert13](https://forum.knime.com/u/Gilbert13)\
**Post date:** [February 1, 2021, 6:13am UTC](https://forum.knime.com/t/string-manipulation-multiple-expressions/30346/3 "2021-02-01T06:13:01Z")

</div>

@elsamuel thank you for solution, but it appears only column that contains “D” extracted.

result  
65200  
65213  
65277  
65212D1  
65242

the “B” does not work.  
where am i wrong?

when i change the “D” first, the the result appears otherwise

---

<div class="post-metadata">

**Author:** ![Gilbert13](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/g/919ad9/32.png) [@Gilbert13](https://forum.knime.com/u/Gilbert13)\
**Post date:** [February 1, 2021, 6:38am UTC](https://forum.knime.com/t/string-manipulation-multiple-expressions/30346/4 "2021-02-01T06:38:12Z")

</div>

@elsamuel it works perfectly when i define it first,  
thanks a lot, i appreciate it.

substr1 = (substr(column(“No Backsheet”), 7, 1) == “D”)  
substr2 = (substr(column(“No Backsheet”), 7, 1) == “B”)  
or1 = or(substr1, substr2)

if (or1)  
{  
substr(column(“No Backsheet”), 2, 7)  
}  
else  
{  
substr(column(“No Backsheet”), 2, 5)  
}

---

<div class="post-metadata">

**Author:** ![ipazin](https://forum-cdn.knime.com/user_avatar/forum.knime.com/ipazin/32/806_2.png) [@ipazin](https://forum.knime.com/u/ipazin)\
**Post date:** [February 1, 2021, 4:03pm UTC](https://forum.knime.com/t/string-manipulation-multiple-expressions/30346/5 "2021-02-01T16:03:23Z")

</div>

Hello @Gilbert13,

alternatively you can use _regexReplace()_ function available both in [String Manipulation](https://kni.me/n/eOn8ibZnxIkY7XhT) and already mentioned Column Expressions node. Here is expressions I used:

`regexReplace($column1$,"..(\\d{5})([D|B].)?.*" ,"$1$2" )`

Suggest to use the first one as should be faster.

Welcome to Community!

Br,  
Ivan

---

<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:** [February 8, 2021, 4:03pm UTC](https://forum.knime.com/t/string-manipulation-multiple-expressions/30346/6 "2021-02-08T16:03:46Z")

</div>

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