< Back to IRCAM Forum

Replace words inside string

hello,

i have the following string:

“text word number word”

i need to substitute word with new-word. the result should be:

“text new-word number new-word”

something like this but for string/characters
image

is there any function available in om?
any hint would be appreciated!

best
rc

Dear rc,

It works with substitute if you are using a list of strings:

I don’t know if this is what you want?

Best
K
PS: here is the patch:
replace-words.omp (2.7 KB)

Dear K

thanks for the patch!
it solves the substitution part
but now, is there a function to turn “text word number word” into (“text” “word” “number” “word”)?

best
rc

Dear RC,

THe output IS a separate string list:
OM => (“text” “new-word” “number” “new-word”)

It is just the Text-Box display that shows strings as symbols.

Best
K

Yes, I know, but my input is “text word number word” as mentioned in the original post, so in order to use substitution one should split the string into a list of strings.

Ok, got it.

You can use:

(split-by-one-space “text word number word”)

=> (“text” “word” “number” “word”)

:slight_smile:
K

1 Like

amazing, thanks!

is there a way to find this kind of functions in om?

best
rc

Yes it is an OM function.
You can find it in code/projects/fluid/player/fluid-info.lisp

(you can locate it by selecting the function and typing e)

Best
K