freelanceprogrammers.org Forum Index » Perl

Re: How to cenvert to ascii


View user's profile Post To page top
dodekaedergu... Posted: Tue Jun 01, 2004 10:59 am


Joined: 03 May 2004

Posts: 8
Re: How to cenvert to ascii
> How to convert the following string to regular ascii:
>
> mailto:we

I guess you mean: How do you get the character equivalent to ASCII code
109 etc.

(1) (split /;/) turns your string into a list of items.
(2) Of each item, drop the first two characters (&#) and any leading
zero
(to avoid being it interpreted as octal in step 3)
(3) You end up with a list of numbers 109 97 105 etc. Use the chr
function
to turn it into a character.

Ronald
Reply with quote
Send private message
View user's profile Post To page top
perl_jam03 Posted: Tue Jun 01, 2004 7:45 pm


Joined: 05 May 2004

Posts: 16
Re: How to cenvert to ascii
This is the optimal solution if all characters are codified using the
&___; notation. If you notice, the colon (`:`) is not codified, which
makes the process a little bit more difficult.

I played around with the string for a while but gave up. I thought of
the following:

1) Sequentially parsing the string from beginnign to end using a
construct like /^(&#d+?;)/
1a) If no match is found, extracct the next character `as is`
2) Processing the extracted string using your routine from steps 2 and
3 below
3) Extracting it from the original string with substring
4) Return to step 1 until all the string is done

Any other suggestions?
Rex

--- fischron.external@... wrote:
> > How to convert the following string to regular ascii:
> >
> > mailto:we
>
> I guess you mean: How do you get the character equivalent to ASCII
> code
> 109 etc.
>
> (1) (split /;/) turns your string into a list of items.
> (2) Of each item, drop the first two characters (&#) and any leading
> zero
> (to avoid being it interpreted as octal in step 3)
> (3) You end up with a list of numbers 109 97 105 etc. Use the chr
> function
> to turn it into a character.
>
> Ronald
>
>
> ------------------------ Yahoo! Groups Sponsor
> --------------------~-->
> Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
> Now with Pop-Up Blocker. Get it for free!
> http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/ndFolB/TM
>
--------------------------------------------------------------------~->
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
Reply with quote
Send private message
View user's profile Post To page top
balour_2000 Posted: Tue Jun 01, 2004 8:58 pm


Joined: 31 May 2004

Posts: 2
Re: How to cenvert to ascii
Allo!

>This is the optimal solution if all characters are codified using the

Here is the solution:

Use regexp replacement instead:

$string =~ s/&#(d+);/chr($1)/ge;

or even better, use a module:

use HTML::Entities;
$string = decode_entities($string);

This work great.

Gilles B.


--
Encore plus de trucs et d`astuces pour Webmasters
http://www.biwi.qc.ca/favori/
More Webmastering trics:
http://www.biwi.qc.ca/favorite/
--
Reply with quote
Send private message
View user's profile Post To page top
perl_jam03 Posted: Wed Jun 02, 2004 7:19 am


Joined: 05 May 2004

Posts: 16
Re: How to cenvert to ascii
Wow. Great solution. This is the one.
Nice going Gilles.
Rex


--- Gilles Beauregard <gilles@...> wrote:
> Allo!
>
> >This is the optimal solution if all characters are codified using
> the
>
> Here is the solution:
>
> Use regexp replacement instead:
>
> $string =~ s/&#(d+);/chr($1)/ge;
>
> or even better, use a module:
>
> use HTML::Entities;
> $string = decode_entities($string);
>
> This work great.
>
> Gilles B.
>
>
> --
> Encore plus de trucs et d`astuces pour Webmasters
> http://www.biwi.qc.ca/favori/
> More Webmastering trics:
> http://www.biwi.qc.ca/favorite/
> --
>
>
>
> ------------------------ Yahoo! Groups Sponsor
> --------------------~-->
> Yahoo! Domains - Claim yours for only $14.70
> http://us.click.yahoo.com/Z1wmxD/DREIAA/yQLSAA/ndFolB/TM
>
--------------------------------------------------------------------~->
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help