Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Perl (http://www.go4expert.com/forums/perl/)
-   -   whitespace remove (http://www.go4expert.com/forums/whitespace-remove-t11265/)

abhisheksainiabhishe 11Jun2008 13:26

whitespace remove
 
If I have a multiline text like..

abcd ef ghi
xyz d e f
d
sjskf s fdf

then how would I be able to remove the spaces (/s+) inside the strings (in middle of the strings).

I thought using doing like...

$string =~ s/\s+/ /g;

would work. but it does not work.

And if above is the way I would end up finally then can I make it like so it would
not alter spaces within <pre> tags like....

#declaring pretags avlyes
my $startPreTag="<pre>";
my $endPreTag="</pre>";


#so the spaces (more than one) will be removed is it is not enclosed by pre tags
$string =~ s/[^$startPreTag]^\s+[^$endPreTag]//;

Please tell me if I am on the right track

None of my appraoches are working. Please advise. Thanks!

pradeep 11Jun2008 14:41

Re: whitespace remove
 
You expression looks like having a space in the replacement portion,
Code: Perl

# Your version
$string =~ s/\s+/ /g;
# Right code
$string =~ s/\s+//g;


For replacement within PRE tags,
Code: Perl

$string =~ /<pre>([^<]+)<\/pre>/gi;
$str = $1;
$str =~ s/\s+//g;
$string =~ s/<pre>([^<]+)<\/pre>/$str/;


This will work only if there is only one occurance of pre in the string, you can also try HTML::Parse for this purpose.

abhisheksainiabhishe 12Jun2008 03:34

Re: whitespace remove
 
got it.
thanks!

XXxxImmortalxxXX 7Jul2008 14:21

Re: whitespace remove
 
DONT SPAM THAT GAY *** GAME called runescape u will pay for spamming those message i swear to god you will. I hate runescape with a passion its the most retardest game ever made U WILL PAY I SWEAR TO GOD ON THAT

shabbir 8Jul2008 10:09

Re: whitespace remove
 
Hi account is banned and all posts removed as well as the site goes into spam sites


All times are GMT +5.5. The time now is 22:54.