Tags:
create new tag
, view all tags

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

TWiki version: TWikiRelease04x01x00
TWiki plugins: SpreadSheetPlugin, ActionTrackerPlugin, CommentPlugin, DateFieldPlugin, EditTablePlugin, ExcelImportExportPlugin, .FileTrackerPlugin, FindElsewherePlugin, FormQueryPlugin, PreferencesPlugin, RecursiveRenderPlugin, SectionalEditPlugin, SlideShowPlugin, TablePlugin, TagMePlugin, WysiwygPlugin
Server OS: CentOS 4.4
Web server: Apache 2.0
Perl version: Perl 5.8.5
Client OS: Windows XP
Web Browser: Firefox 2.0.0.1
Categories: Plugins

-- JasonLuttgens - 17 Jan 2007

Answer

ALERT! 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

Change status to:
Edit | Attach | Watch | Print version | History: r5 < r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r5 - 2007-07-18 - VickiBrown
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.