Is it true that regsub of tcl7.5 (UNIX) is not working correct?
I want to replace all "backslash newline" expressions in a string by
"spaces":
regsub -all "\\\n" $line { } line
It replaces all "n" in the text by "Space" but the "newlines" remain.
What can I do?
Andreas!
a...@kreutler.de
: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -:
: KREUTLER Brauerstr. 50, 76135 Karlsruhe, 0721/824-0 :
: Andreas Engel a...@kreutler.de oder eng...@it.ba-karlsruhe.de :
:----------------------------------------------------------------------:
: Is it true that regsub of tcl7.5 (UNIX) is not working correct?
: I want to replace all "backslash newline" expressions in a string by
: "spaces":
: regsub -all "\\\n" $line { } line
: It replaces all "n" in the text by "Space" but the "newlines" remain.
: What can I do?
If you want replace COMBINATION OF TWO CHARACTERS backslash and n,
you should use either {\\n} or "\\\\n".
Note, that backslashes between quotes are first interpreted by Tcl,
and then by regsub itself. If you want newline character, you should
make Tcl prepare it, becouse \n has no special meaning for reqsub,
but tcl can convert it into actual newline character before passing
to regsub. So, in this case put JUST ONE backslash inside double
quotes.
regsub -all "\n" {This
is
a
multi
line
string
} line
works for me (plain 8.0) as expected.
: Andreas!
And if you want the combination of backslash and newline,
use:
% set line
This is \
a line
% regsub -all "\\\\\n" $line " " res
1
% set res
This is a line
So you scored three out of five backslashes!
Regards,
Sebastian
--
Sebastian Wangnick <sebastian...@eurocontrol.be>
Office: Eurocontrol Maastricht UAC, Horsterweg 11, NL-6191RX Beek,
Tel: +31-433661370, Fax: ~300
Home: Lammersdorfer Str. 61, D-52159 Rott, Tel: +49-2471-2301,
Fax: ~2313, Email: familie....@t-online.de
--
To: pgp-pub...@nic.surfnet.nl, Subject: GET Sebastian Wangnick
GCS/IT d+(-) s:- a C+() U++$ P+ L+ E--- W++(--) N o? K? w++++(---)
!O !M V PS++ PE Y+ PGP?>++ t++ 5-- X- R tv--- b+++ DI? D--(+) G
e+++ h>---- r+++ y++>*
>regsub -all "\\\n" $line { } line
You are a few slashes to short. By using the ""s, you are asking Tcl to
do one level of subsitution (which is required to get the newline), that
becomes:
\<NEWLINE>
Then the regexp also does a level of substitution, turning that simply into
a newline. You want:
regsub -all "\\\\\n" $line { } line
--
Jeffrey Hobbs "I'm really just a Tcl-bot"
jeff.hobbs at acm.org | Jeffrey.Hobbs at oen.siemens.de