help me to replace ascii charecter with some other ascii charector or text

help me to replace ascii charecter with some other ascii charector or text

Post by Kasi ramanath » Wed, 29 Jan 2003 21:23:37



dear friends i'm in work place and i'm facing a problem of replacing an ascii character with some other ascii character i cut the ascii character from my word document and pasted it in my pear programme but the result is not as i expected. plese give me answer with simple codeing and also say me how to use word file as input file. my coding is as below


$t= $ARGV;
print "$t\n";
$ln=~s/
file://gis;

$ln=~s/'/,/gis;
$ln=~s/[      ]/ /gis;
$ln=~s/[cr]//gis;
$ln=~s/[abc]//gis;
$ln=~s/_/_/gis;
$ln=~s/y/+/gis;
$ln=~s/?/^/gis;
$ln=~s/%/%/gis;
$ln=~s/</</gis;
$ln=~s/'/'/gis;
$ln=~s/'/'/gis;
$ln=~s/"/"/gis;
$ln=~s/"/"/gis;
$ln=~s/o//gis;
$ln=~s/-/--/gis;
$ln=~s/-/----/gis;
$ln=~s/?/~/gis;
$ln=~s/>/>/gis;
print $ln;
open (H, ">$ARGV");
print H $ln;

Catch all the cricket action. Download Yahoo! Score tracker

 
 
 

help me to replace ascii charecter with some other ascii charector or text

Post by Simr » Thu, 30 Jan 2003 07:11:51


Sounds like you are trying to copy/paste control characters... there are
different ways to include them into files depending on what editor you
are using...

eg. if using vi/vim you can do:

      Control-v Control-m

to get a ^M into the file...


> dear friends i'm in work place and i'm facing a problem of replacing an ascii character with some other ascii character i cut the ascii character from my word document and pasted it in my pear programme but the result is not as i expected. plese give me answer with simple codeing and also say me how to use word file as input file. my coding is as below



> $t= $ARGV;
> print "$t\n";
> $ln=~s/
> file://gis;

> $ln=~s/'/,/gis;
> $ln=~s/[      ]/ /gis;
> $ln=~s/[cr]//gis;
> $ln=~s/[abc]//gis;
> $ln=~s/_/_/gis;
> $ln=~s/y/+/gis;
> $ln=~s/?/^/gis;
> $ln=~s/%/%/gis;
> $ln=~s/</</gis;
> $ln=~s/'/'/gis;
> $ln=~s/'/'/gis;
> $ln=~s/"/"/gis;
> $ln=~s/"/"/gis;
> $ln=~s/o//gis;
> $ln=~s/-/--/gis;
> $ln=~s/-/----/gis;
> $ln=~s/?/~/gis;
> $ln=~s/>/>/gis;
> print $ln;
> open (H, ">$ARGV");
> print H $ln;

> Catch all the cricket action. Download Yahoo! Score tracker


 
 
 

help me to replace ascii charecter with some other ascii charector or text

Post by David Eas » Thu, 30 Jan 2003 06:43:01


For starters, it looks like most of your replacements should use the tr///
function (also known as y///).

http://www.perldoc.com/perl5.8.0/pod/perlop.html

For seconds, $ln=~s/'/'/gis; looks like a no-op to me.

 
 
 

help me to replace ascii charecter with some other ascii charector or text

Post by John W. Kra » Thu, 30 Jan 2003 09:01:17



> dear friends i'm in work place and i'm facing a problem of replacing an
> ascii character with some other ascii character i cut the ascii character
> from my word document and pasted it in my pear programme but the result
> is not as i expected. plese give me answer with simple codeing and also
> say me how to use word file as input file. my coding is as below

You _should_ be use'ing warnings and strict when developing your code.

It is more efficient to undef the input record separator and slurp the
file into a scalar.

Quote:> $t= $ARGV;
> print "$t\n";
> $ln=~s/
> file://gis;

> $ln=~s/'/,/gis;
> $ln=~s/[????? ]/ /gis;s;
> $ln=~s/[cr]//gis;
> $ln=~s/[abc]//gis;
> $ln=~s/_/_/gis;
> $ln=~s/y/+/gis;
> $ln=~s/^/^/gis;
> $ln=~s/%/%/gis;
> $ln=~s/</</gis;
> $ln=~s/'/'/gis;
> $ln=~s/'/'/gis;
> $ln=~s/"/"/gis;
> $ln=~s/"/"/gis;
> $ln=~s/o//gis;
> $ln=~s/-/--/gis;
> $ln=~s/-/----/gis;
> $ln=~s/~/~/gis;
> $ln=~s/>/>/gis;

All of your substitutions use the /s option which determines wheather
the dot (.) matches a newline or not.  Since none of the regular
expressions uses a dot, the /s option is not needed.  All of your
substitutions use the /i option which affects how alphabetic characters
are matched but most of your regular expressions do not contain
alphabetic characters.

Quote:> print $ln;
> open (H, ">$ARGV");

You should _always_ verify that the file was opened correctly.

Quote:> print H $ln;

It looks like you want to modify the file "in-place" and perl provides a
method to do this.

#!/usr/bin/perl -w
use strict;

$/  = undef;
$^I = '.bak';

while ( <> ) {
    print "$ARGV\n";

    s/\nfile://gi;

    tr/'?????\177/,\177/;
    tr/crabc//d;
    tr/_y^%<'"o/_+^%<'"/;

    s/-/--/g;
    s/-/----/g;

    tr/~>/~>/;
    }

__END__

John
--
use Perl;
program
fulfillment

 
 
 

help me to replace ascii charecter with some other ascii charector or text

Post by R. Joseph Newt » Thu, 30 Jan 2003 13:23:13


Kais,

Those are not ASCII characters.  Nor arem ost of them control characters.  They are extended charcters, based on an unsigned, rather than signed, char type.  ASCII proper only extends to character 127, the upward-pointing triangle [or the character so rendered by my command environment].  The other characters also print at my DOS prompt, and all seem to be accented or otherwise top-decorated latin characters.  Unfortunately, these do not translate into ASCII very well in many formats [including e=mail].  See the readout below for an illustration.


> $ln=~s/'/,/gis;
> $ln=~s/[      ]/ /gis;

and...


> $ln=~s/'/,/gis;
> $ln=~s/[????? ]/ /gis;s;

I took the part from the opening bracket to end-of-line from each of those second lines, and used ord() to get the ASCII/Unicode value:

#!/usr/bin/perl -w

use strict;

open IN, "<unichars.txt";

close IN;


  print "\n$Line\n";

    my $num = ord($_);
   print "$num\n";
  }

Quote:}

Kasi's original

91
143
144
157
129
141
127
93
47
127
47
103
105
115
59
10

John's "copy:"

91
63
63
63
63
63
127
93
47
127
47
103
105
115
59
115        //extra semicolon
59         //extra 's'
10

If you want to actually use the non-ASCII characters contained in MS Word, you will have to learn the wider character set used.  You may also need to come up with a list of MS Word control characters.

I'm not sure what the solution is.  I assume that part of the work of a locale object is to abstract the difference by mapping an appropriate slice of unicode to the first 127 characters, according to usage within the language group.

Unfortunately, you were extremely vague about which characters you wish to change to which.  What are the results you expected to see?  This may be part of the problem.  It is NEVER a good idea to try to code a problem until you can explain in plain language EXACTLY what you want to see happen.  An ameoba is a genius compare to even the most sophisticated processor.  No compiler or machine can fill in the blanks for you.  They are machines, not mind-readers.

Please write, include a little less code, but explain exactly what you expect each line you do send to do.  People will be able to help you much more.

Joseph

 
 
 

help me to replace ascii charecter with some other ascii charector or text

Post by John W. Kra » Thu, 30 Jan 2003 22:11:46



> If you want to actually use the non-ASCII characters contained in MS Word,
> you will have to learn the wider character set used.  You may also need to
> come up with a list of MS Word control characters.

You might get some help by looking at the source for Demoronizer

http://www.fourmilab.ch/webtools/demoroniser/

John
--
use Perl;
program
fulfillment

 
 
 

help me to replace ascii charecter with some other ascii charector or text

Post by R. Joseph Newt » Fri, 31 Jan 2003 15:06:52



> You might get some help by looking at the source for Demoronizer

> http://www.fourmilab.ch/webtools/demoroniser/

Hi John,

Well, it was a cute read, I must say.  The only problem is that I'm not sure quite what application he was talking about.  You see, I just tested the text you suggested, along with a couple other lines of my own surrounding it.  I just re-installed Office 2K so I haven't gotten around to killing the Auto-Correct and "Autoformat as you type" features.  So I got the smart quotes and dashes.  The dash [0x2c] remained, but the quotes were all turned to standard 0x27 '"'.  I threw in a couple other goodies, too, the most revealing of which was two ways to get a copyright to print in Word.

In the original Word in doc format, I used the insert|symbol... feature to insert the copyright mark before MS.  I used a text escape later, before apostrophes.  When I saved as text, the inserted symbol took on varied translations, but the text (c) was restored to the form originally entered.

#!/usr/bin/perl -w

use strict;

open IN, "<Okay.txt";

close IN;

#  my $Line = <IN>;

  print "\n$Line\n";

    my $num = ord($_);
   print "$_ $num\n";
  }

Quote:}

Perl Output:
E:\d_drive\perlStuff\guests>unichars.pl

Okay, here's a more extended test of the "moron" characteristics of (MS -Word.

O 79
k 107
a 97
y 121
, 44
  32
h 104
e 101
r 114
e 101
' 39
s 115
  32
a 97
  32
m 109
o 111
r 114
e 101
  32
e 101
x 120
t 116
e 101
n 110
d 100
e 101
d 100
  32
t 116
e 101
s 115
t 116
  32
o 111
f 102
  32
t 116
h 104
e 101
  32
" 34
m 109
o 111
r 114
o 111
n 110
" 34
  32
c 99
h 104
a 97
r 114
a 97
c 99
t 116
e 101
r 114
i 105
s 115
t 116
i 105
c 99
s 115
  32
o 111
f 102
  32
( 40
M 77
S 83
  32
- 45
W 87
o 111
r 114
d 100
. 46
  32
  32

 10

"Halt," he cried, "this is the police!"

" 34
H 72
a 97
l 108
t 116
, 44
" 34
  32
h 104
e 101
  32
c 99
r 114
i 105
e 101
d 100
, 44
  32
" 34
t 116
h 104
i 105
s 115
  32
i 105
s 115
  32
t 116
h 104
e 101
  32
p 112
o 111
l 108
i 105
c 99
e 101
! 33
" 34

 10

What did he mean by 'single quotes', anyway?  All I see is (c)apostrophes.

W 87
h 104
a 97
t 116
  32
d 100
i 105
d 100
  32
h 104
e 101
  32
m 109
e 101
a 97
n 110
  32
b 98
y 121
  32
' 39
s 115
i 105
n 110
g 103
l 108
e 101
  32
q 113
u 117
o 111
t 116
e 101
s 115
' 39
, 44
  32
a 97
n 110
y 121
w 119
a 97
y 121
? 63
  32
  32
A 65
l 108
l 108
  32
I 73
  32
s 115
e 101
e 101
  32
i 105
s 115
  32
( 40
c 99
) 41
a 97
p 112
o 111
s 115
t 116
r 114
o 111
p 112
h 104
e 101
s 115
. 46

 10

 10

E:\d_drive\perlStuff\guests>
EndPerlOutput

Word Output <<EndWord # pasted from Word into Netscape Communicator 4.79 on Win 2K
Okay, here's a more extended test of the moron characteristics of ?MS -Word.
Halt, he cried, this is the police!
What did he mean by single quotes, anyway?  All I see is ?apostrophes.

EndWord

NotePad Output
Okay, here's a more extended test of the "moron" characteristics of (MS -Word.
"Halt," he cried, "this is the police!"
What did he mean by 'single quotes', anyway?  All I see is (c)apostrophes.

End Word

Word after closing and re-opening:
Okay, here's a more extended test of the "moron" characteristics of (MS -Word.
"Halt," he cried, "this is the police!"
What did he mean by 'single quotes', anyway?  All I see is (c)apostrophes.

End Word

It is clear from this snippet that the copyright symbol does get translated differently.  In some cases it comes out as lt;, in others it comes out as a left paren.  I don't see any characters that had been inserted for ASCII showing this effect, though.

Perhaps the author was using the '97 version, and had not bothered to recheck his prejudices in the last three years.

Joseph

 
 
 

help me to replace ascii charecter with some other ascii charector or text

Post by David Eas » Sat, 01 Feb 2003 11:27:11



> Perhaps the author was using the '97 version, and had not bothered to

recheck his prejudices in the last three years.

Quote:

> Joseph

Given the page is dated January 16th, 1998, you may be right.

I am no Microsoft basher. In fact I have an MCSE cert and I used to work
with those people and it was a great experience. However, in Word 2002,
note: when I save a Word document as HTML, it puts a lot of proprietary, and
seemingly unnecessary, XML in it, and it seems that this is because it
assumes you later may want to save it as a DOC file again (but maybe you
really have no such intention). So perhaps there is a need for a
de-XML-ifier these days?

Personally I have an automatic prejudice against WYSIWYG HTML editors
anyway.

 
 
 

1. HELP: How to translate ASCII-CODE to ASCII-Charakters

Hello,

I have a stupid Problem:
I have to translate a lot of ASCII-Codenumbers (49,54,110....) into
Charakters.

How can I do this? Do I have to make a

if ($number == 49){ print ']';}

Or is there an better, faster, smarter way.

I could not find anything about that, maybe there is a possibility with
pack/unpack or printf??

Thanks for Help,

Bastian

2. Are Matrox lying?

3. ascii-ascii compression

4. Controlling the IE4

5. ascii-2-ascii filter for VI?

6. [MySQL 3.23.39 sparc/linux: architecture lacks fast mutexes ]

7. test : BITNET: ASCII - EBCDIC - ASCII

8. HAHAHAHahahah

9. How to translate ASCII-CODE to ASCII-Charakters

10. CP/M ASCII to PC ASCII

11. Conv. PostScript to ASCII text. HELP!

12. HELP: VBA Macros for writing to ASCII (Text) files

13. HELP with importing data from ascii text file