Question
I have been using the Spreadsheet plugin's TRANSLATE and SUBSTITUTE functions to do some nice things for string manipulation. The one thing I cannot figure out how to do is simply delete a character from a string.
For instance, I run a search and it has some spaces in it (single spaces, not multiple, so I cannot use TRIM). I want to remove those single spaces. I cannot figure out how to do this.
Ideas?
Environment
--
JasonLuttgens - 17 Jan 2007
Answer
If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.
Well, unfortunately I didn't have enough time to wait. I wrote a quick plugin to pass parameters to a standard Perl substitute expression (a la $string =~ s/this/that/g) and return the result. That did the trick.
But I would still like to know if TWiki has some built-in ability to do character deletion in a string.
--
JasonLuttgens - 17 Jan 2007
That is a bit tricky with the current function set. You can use
$SUBSTITUTE(), but you can't define a space as the "from" parameter. So you can first use
$TRANSLATE() to translate the space temporarily into another character. You also need to watch out for potential commas in the string;
$SUBSTITUTE() can't handle them, so you need to temporarily translate them into another char as well.
Example (view raw text) of removing spaces from: "a string with comma, and spaces":
%CALC{$TRANSLATE($SUBSTITUTE($TRANSLATE(a string with comma, and spaces, $sp$comma, $CHAR(29)$CHAR(30)), $CHAR(29)), $CHAR(30), $comma)}%
astringwithcomma,andspaces
--
PeterThoeny - 18 Jan 2007
Interesting, ok, I see. Good to know. Thanks!
--
JasonLuttgens - 18 Jan 2007