Translating & 
Author Message
 Translating &

Can anyone tell me why
   gsub(/&/,"&")
doesn't work?

   gsub(/"/,"\"")
and a lot of similar lines work. I've tried with slashes here and
there too, but it just refuses to be translated. I'm using DOS gawk
3.0.3, haven't had a chance to try it in Linux yet. I'd like to try to
avoid using sed just for this little thing...



Fri, 09 Jun 2000 03:00:00 GMT  
 Translating &


: Can anyone tell me why
:    gsub(/&/,"&")
: doesn't work?

& has a special meaning in gsub, meaning "matched text"
use \& to get a literal &
However, use \\& , as one \ gets swallowed, you need \\ to say
you really mean \

:    gsub(/"/,"\"")
: and a lot of similar lines work. I've tried with slashes here and
: there too, but it just refuses to be translated. I'm using DOS gawk
: 3.0.3, haven't had a chance to try it in Linux yet. I'd like to try to
: avoid using sed just for this little thing...

--
Ian Stirling.   Designing a linux PDA, see  http://www.mauve.demon.co.uk/
----- ******* If replying by email, check notices in header ******* -----
Two fish in a tank: one says to the other, you know how to drive this thing??



Fri, 09 Jun 2000 03:00:00 GMT  
 Translating &


Quote:
> Can anyone tell me why
>    gsub(/&/,"&")
> doesn't work?

The gawk manual says:

  As in sub, the characters '&' and '\' are special...

Quote:
>    gsub(/"/,"\"")
> and a lot of similar lines work. I've tried with slashes here and
> there too, but it just refuses to be translated. I'm using DOS gawk

The ampersand in the replacement string is used to indicate the substring
matched.  See the docs for "More about `\' and '&' with sub, gsub,
and gensub" for the proper escape.

--



Fri, 09 Jun 2000 03:00:00 GMT  
 Translating &



% Can anyone tell me why
%    gsub(/&/,"&")
% doesn't work?

&, in replacement text, represents the entire matched expression.
You can get around this by putting sufficient back-slashes in front of it.
 gsub(/&/,"\\&")

The first back-slash escapes the second back-slash (for the string). The
second one escapes the & (for the RE replacement).

--

Patrick TJ McPhee
East York  Canada



Sat, 10 Jun 2000 03:00:00 GMT  
 Translating &

Quote:

> Can anyone tell me why
>    gsub(/&/,"&")
> doesn't work?

>    gsub(/"/,"\"")
> and a lot of similar lines work. I've tried with slashes here and
> there too, but it just refuses to be translated. I'm using DOS gawk
> 3.0.3, haven't had a chance to try it in Linux yet. I'd like to try to
> avoid using sed just for this little thing...

if you want to substitue '&' with '&' try this:
     gsub(/&/, "\\&")
because the '&' represente the matched string !

best regard,

Herve Le Follic.



Sat, 10 Jun 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. ABC Templates @#$%^&*&&*&*!!!!!!

2. Cybersex--(*&$%*&(*&^% C programmers

3. translating forms&tables from APLII to APLIII

4. translating ä and others

5. two inscrutable string words - translate & transpose

6. Error during Xilinx P&R translate stage

7. hpux && snapshot && ./configure

8. TCL2C && MS VC++ && TCL8.0.3plus

9. *&$%*&%$ OBDC!!!

10. I am frustrated (*%^&^*&##

11. DataFlex & Q&A Conversion to Topspeed

12. Data Corruption in Clipper & Windows 2000

 

 
Powered by phpBB® Forum Software