Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

How to remove portion of the text from a given field?

Quote Reply
How to remove portion of the text from a given field?
Hello,


Say I have a category field called "Custom_Name" and the Custom_Name have the same prefix for each category say "prefix1_" for each subcategories.

I have different prefixes for different top categories.

How to declare a variable where I can define the prafix and then remove it form Custom_Name field.


I have a global called "substitute" which replaces space with underscore:

Code:

sub {

my $action = $_[0];

if ($action eq "underscore") {$_[1] =~ tr/ /_/; return $_[1]; }
else { return "Invalid action passed..."; }

}
then i call the global like this

Code:
<%substitute('underscore',$Custom_Name)%>

how to modify this to achieve what in I need?

Thanks in advance.
Quote Reply
Re: [AMIXIMA] How to remove portion of the text from a given field? In reply to
Hi,

If I'm understanding you correctly, this should do the trick (same global name as before, just overwrite it);

Code:
sub {
if ($_[0] eq "underscore") {
$_[1] =~ s/ /_/g;
$_[1] =~ s/prefix1_//g;
return $_[1];
} else { return "Invalid action passed..."; }
}

Then call the same way as you currently do.

Hope that helps :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!