Hello,
I have a column with strings lookig like this :
ABDC01234
ABCD56789
I would like to replace the 6th positon of the strinf with an / but only if its a zero. So I would like my result to look like this
ABCD/1234
ABCD/56789
So far I used the string manipulation node
join(substr(string($Columnname$),0,6), β/β, substr(string($Columnname$),6))
but this just inserts the /. Has anybody an idea how to do that?
Sorry if this question was already asked, I couldnt find anything.
Thanks in advance
ipazin
October 30, 2020, 11:29am
2
Hello @Francesca ,
this expressions should replace 0
on 6th position with /
join(substr($col$,0,5), replace(substr($col$,5,1),"0" ,"/"), substr($col$,6))
Br,
Ivan
Thank you but it doesnβt solve my problem entirely. Because it doesnβt insert the / for strings with no zero. so the result is
ABCD/1234
ABCD56789
but I want
ABCD/1234
ABCD/56789
ipazin
October 30, 2020, 1:04pm
4
Hello @Francesca ,
I see now. Then you can use Column Expressions node with following expression:
if( substr(column(βcolβ),5,1) == β0β) {
join( substr(column(βcolβ),0,5 ), β/β, substr(column(βcolβ),6))
}
else
{
join( substr(column(βcolβ),0,5 ), β/β, substr(column(βcolβ),5 ))
}
Br,
Ivan
2 Likes
Hi
not sure if your string is more complicated then your examples but if not then
regexReplace(substr($column1$,0 ,4 ) +"/"+substr($column1$,4),"/0","/") with string manipulation could do the job
(normal replace should also work i suppose)
2 Likes
Thanks Ivan and Daniel for your solutions. Both worked!
I have another questions regarding string manipulation. What if I wanted to insert the β/β not at a certain position but for example after the second blank space?
So my strings would look like
AB CD 1234
AB F 1234
and I wanted to get
ABCD/1234
ABF/1234
is that also possible with the regexreplace?
ipazin
November 2, 2020, 12:15pm
7
Hello @Francesca ,
here is one that should hopefully do the trick:
regexReplace($column1$,"(\\w+) (\\w+) (.*)" ,"$1$2/$3" )
In case there is more than 3 groups separated with spaces use removeChars() function around above expressions to remove all space characters.
Br,
Ivan
2 Likes
Thank you Ivan! That solves my problem
1 Like
system
Closed
November 9, 2020, 12:31pm
9
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.