Page 1 of 1

Remove part of string??

Posted: 04 Dec 2019 11:51
by Lucy
Hey.. how can i trim, split, etc a string?
I have a gile that contains something similar to this: {text=Clear}
I want to remove the "{text=" as well as the end "}". I have tried:
-filename = "test.mp3";
name = left(filename, length(filename) - 4);
And tried with right command.
I have also tried putting the text in an object and using remove.
Ultimately i have no idea how to do it

Re: Remove part of string??

Posted: 04 Dec 2019 17:33
by Desmanto
Use replace().

Code: Select all

text = '{text=Clear}';
rep = replace(replace(text, '{text=', ""), '}', "");
However, once your data started to become more and more complex, using replace will be so painfully long.

Better method is to use regex.

Code: Select all

text = '{text=Clear}';
regex = findAll(text, '\\{text=(.*)\\}', true)[0][1];
{} are special char in regex, so have to be escaped with backslash. The backslash itself is also special char again Automagic scripting, have to escaped again, ends up double backslash to escape the curly braces.
(.*) to capture any text in between.
[0][1] to access the capture group 0 (first whole capture) and then the subgroup 1.

Re: Remove part of string??

Posted: 04 Dec 2019 18:05
by Lucy
Oh fantastic as usual darling... thankyou.