Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Auto Convert ?

Quote Reply
Auto Convert ?
Hello all,

The tag below using to convert any capital letter to small letter, but how to make any starting word automatically convert to capital letter, for example the word 'post new message' to 'Post New Message'.

Please help...

Description_Filter =>
sub {
my $tags = shift;
my $description = $tags->{Description};
$description = GT::CGI::html_escape($description);
$description =~ s/A/a/g;
$description =~ s/B/b/g;
$description =~ s/C/c/g;
$description =~ s/D/d/g;
$description =~ s/E/e/g;
$description =~ s/F/f/g;
$description =~ s/G/g/g;
$description =~ s/H/h/g;
$description =~ s/I/i/g;
$description =~ s/J/j/g;
$description =~ s/K/k/g;
$description =~ s/L/l/g;
$description =~ s/M/m/g;
$description =~ s/N/n/g;
$description =~ s/O/o/g;
$description =~ s/P/p/g;
$description =~ s/Q/q/g;
$description =~ s/R/r/g;
$description =~ s/S/s/g;
$description =~ s/T/t/g;
$description =~ s/U/u/g;
$description =~ s/V/v/g;
$description =~ s/W/w/g;
$description =~ s/X/x/g;
$description =~ s/Y/y/g;
$description =~ s/Z/z/g;
return $description;
}
Quote Reply
Re: [reenee] Auto Convert ? In reply to
Ack, you actually use that?

You can do the same job in one line:

$description = lc($description);

...as for your other question:

$description =~ s/^(\w)/\U$1/;

Last edited by:

RedRum: Mar 6, 2002, 5:09 AM
Quote Reply
Re: [RedRum] Auto Convert ? In reply to
Thanks Paul,

Its work but it doesnt like what i need, it just convert for example 'post new message' into 'Post new message', what i need is to be 'Post New Message'

Please help and thank you so much.

sub {
my $tags = shift;
my $description = $tags->{Description};
$description = GT::CGI::html_escape($description);
$description = lc($description);
$description =~ s/^(\w)/\U$1/;
return $description;
}
Quote Reply
Re: [reenee] Auto Convert ? In reply to
Oops sorry I misread your post.

Try:

sub {
my $tags = shift;
my $description = $tags->{Description};
$description = GT::CGI::html_escape($description);
$description = lc($description);
$description =~ s/\b(\w)/\U$1/g;
return $description;
}

Last edited by:

RedRum: Mar 6, 2002, 5:27 AM
Quote Reply
Re: [RedRum] Auto Convert ? In reply to
Thanks again Paul,

Its work.
Quote Reply
Re: [reenee] Auto Convert ? In reply to
Oppss...Sorry

One more thing, i try to include the tag below to make any word 'Of' into 'of', but what happen is, its also convert the word 'Official' to 'official', how to make it just convert single word 'Of' ?

$description =~ s/Of/of/g;

Please help.
Quote Reply
Re: [reenee] Auto Convert ? In reply to
Try:

$description =~ s/\bOf\b/of/g;
Quote Reply
Re: [RedRum] Auto Convert ? In reply to
Its work, Thanks Paul.

But one thing happen, any of ' " ' and ' & ' now change to &Quot; and &Amp;, is it effect from tag below ?

Please help.

sub {
my $tags = shift;
my $description = $tags->{Description};
$description = GT::CGI::html_escape($description);
$description = lc($description);
$description =~ s/\b(\w)/\U$1/g;
$description =~ s/\bOf\b/of/g;
return $description;
}

Last edited by:

reenee: Mar 6, 2002, 6:36 AM
Quote Reply
Re: [reenee] Auto Convert ? In reply to
It might be to do with GT::CGI::html_escape .....if not, try changing:

return $description;

to

return \$description;
Quote Reply
Re: [RedRum] Auto Convert ? In reply to
return $description;

to

return \$description;

It doesnt work, Please help...
Quote Reply
Re: [reenee] Auto Convert ? In reply to
Try removing the GT::CGI::html_escape bit.....

Last edited by:

RedRum: Mar 6, 2002, 7:15 AM
Quote Reply
Re: [RedRum] Auto Convert ? In reply to
Hi Paul,

Try removing the GT::CGI::html_escape bit ? Like below ?

sub {
my $tags = shift;
my $description = $tags->{Description};
$description = GT::CGI::html_escape($description);
$description = lc($description);
$description =~ s/\b(\w)/\U$1/g;
$description =~ s/\bOf\b/of/g;
return $description;
}

To:

sub {
my $tags = shift;
my $description = $tags->{Description};
$description = ($description);
$description = lc($description);
$description =~ s/\b(\w)/\U$1/g;
$description =~ s/\bOf\b/of/g;
return $description;
}