Fri Dec 03, 2021 1:51 pm
Login Register Lost Password? Contact Us

How to do multiple "FindReplace" for a single string value?

Questions around writing code and queries

Thu Nov 12, 2015 2:08 am Change Time Zone


I have a string "ABCDE"

with another string array:

I wanna replace all the letters in Group B From Group A to the letter "Z", so the result is:


FindReplace can only accept one string, in the other languages we have foreach /for……loop. But how to implement that in ECL? Please don't use FindReplace three times, because we don't know how many replacement chars there are in the string array. So this solution should be general enough:)
Posts: 8
Joined: Fri Nov 06, 2015 1:05 am

Thu Nov 12, 2015 3:08 pm Change Time Zone


You can use the STD.Str.SubstituteIncluded() function to do exactly that, just like this:
Code: Select all
STD.Str.SubstituteIncluded('ABCDE', 'ABD', 'Z');


Community Advisory Board Member
Community Advisory Board Member
Posts: 1606
Joined: Wed Oct 26, 2011 7:40 pm

Tue Jul 03, 2018 4:47 pm Change Time Zone

Just noticed this post.

You dont have to use a library function. The language itself has this functionality:
Code: Select all
s := 'ABCDE';

I always use a language feature over a library function if there is a choice as the compiler can be clever with a language construct and might fold the whole expression away to nothing. With a library function it's forced to perform a call (which is not cheap) and all register tracking/ optimizations are lost.

Posts: 442
Joined: Sat Oct 01, 2011 7:26 pm

Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest