Gossamer Forum
Home : General : Perl Programming :

Stripping character(s) from string

Quote Reply
Stripping character(s) from string
Is there a simpler way to strip a particular character (carriage return) from a string without going through the string chracter by character in a for...next loop? Note that that there may be one or more characters to strip out.

Dan Smile
Quote Reply
Re: Stripping character(s) from string In reply to
The "g" says to replace all occurances of "\n" with " " in the specified string. Intuitive, ain't it? Wink
Quote Reply
Re: Stripping character(s) from string In reply to
Thanks!

Dan Smile
Quote Reply
Re: Stripping character(s) from string In reply to
Dan,

Try this:

$modified_variable_string = $unmodified_string;
$modified_variable_string =~ s/\n//g;

How this works:
s - search string for
whatever is in between the first two / /
In this case \n
Then between the secon and third / /
will be the character you want to replace with.

I dont know what the g does but it is needed...

Rod
Quote Reply
Re: Stripping character(s) from string In reply to
Ahhh...I see said the blind man! Smile

Thanks Bobsie...I learn something new every day...perl is phat but sometimes it just doesn't make very much much sense!

It's like with the searching for a pattern match
$myvar =~ /Contains/i;

What does the i stand for? "Intrigue"... Smile

Rod
Quote Reply
Re: Stripping character(s) from string In reply to
/i makes it case-insensitive

Dan Smile
Quote Reply
Re: Stripping character(s) from string In reply to
Oh cool...so is it really needed then when doing a pattern search? I mean I tried it a coupla times without and I'd get 500 error...of course other problems were there too but...

I guess I'll just have to try it! Scary to think I've actually written my own progs and I don't know what half this stuff actaully means...even a shopping cart with real-time processing! Now I understand why no-one wants to use it! Smile

Rod
Quote Reply
Re: Stripping character(s) from string In reply to
*heh heh heh*

Know what you mean Rod, but you gotta learn somehow, huh? I was just thinking to myself yesterday, I must find a way to make that matching routine in *my* shopping cart case insensitive, and lo! I drop in here and there's my answer before I even get a chance to ask!

I swear if it wasn't for this forum, dbMan, Matt's Script Archive and Selena Sol, I'd still be trying to figure out "Hello World!"! Smile

Long live Gossamer Threads is all I can say! Smile

adam