Gossamer Forum
Home : Products : DBMan : Customization :

Removing characters from string?

Quote Reply
Removing characters from string?
Is there a routine to remove a character such as the - before printing?
For example:

aa-64-23-98
should print as
aa642398

Thanks ahead!
Chris
Quote Reply
Re: Removing characters from string? In reply to
Yep. Really easy.

$variable =~ s/-//g;

The "s" means to substitute.
The next section is where you put the thing you want replaced.
The next section is where you put what you want to replace it with -- in this case nothing.
The "g" means to do it globally -- every time it appears. Without the "g" it would just replace one of them.


------------------
JPD


[This message has been edited by JPDeni (edited February 26, 1999).]
Quote Reply
Re: Removing characters from string? In reply to
Thanks for the info!
One thing.
How do I incorporate this into DBMan?

The string in question is an item number in my database. It is $rec{'Itemno'}. I am trying to cut down on database fields so I want to use the item number also as a javascript function. You can't have funky characters as javascript functions, so I need the dashes taken out before it prints.

I need to know, how can I put this in my SUB_HTML_RECORD in my HTML.PL file.

This is how I tried it:
|;
if ($rec{'Itemno'}) {
print qq|
$rec{'Itemno'} =~ =~ s/-//g;|;
}
print qq|

Doesn't work. It prints ac-46-wh-98 =~ =~ s/-//g;


Thanks for any help!
Quote Reply
Re: Removing characters from string? In reply to
Take out the hyphens before you print it out.

|;
if ($rec{'Itemno'}) {
$rec{'Itemno'} =~ s/-//g;
print $rec{'Itemno'};
}
print qq|

That should do it.

------------------
JPD

BTW, I made a mistake on my earlier post. I fixed it.

[This message has been edited by JPDeni (edited February 26, 1999).]
Quote Reply
Re: Removing characters from string? In reply to
This works great!

How about removing more than one character?
Quote Reply
Re: Removing characters from string? In reply to
Never mind I figured it out, sorry to bother you!
I am more than pleased with the support around here! This was the best $100 I ever spent!