Message from discussion
one-liner for characater replacement
Path: g2news1.google.com!news1.google.com!news.glorb.com!wn11feed!worldnet.att.net!bgtnsc04-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail
From: "James Giles" <jamesgi...@worldnet.att.net>
Newsgroups: comp.lang.fortran
References: <b35fe8c6-8cb4-49a4-955c-29343c54cbe3@b1g2000hsg.googlegroups.com>
Subject: Re: one-liner for characater replacement
Lines: 31
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
X-RFC2646: Format=Flowed; Original
Message-ID: <Vy%Xj.354705$cQ1.150699@bgtnsc04-news.ops.worldnet.att.net>
Date: Sun, 18 May 2008 19:36:21 GMT
NNTP-Posting-Host: 12.72.112.164
X-Complaints-To: abuse@worldnet.att.net
X-Trace: bgtnsc04-news.ops.worldnet.att.net 1211139381 12.72.112.164 (Sun, 18 May 2008 19:36:21 GMT)
NNTP-Posting-Date: Sun, 18 May 2008 19:36:21 GMT
Organization: AT&T Worldnet
analys...@hotmail.com wrote:
> I want to replace every occurrence of a dash in a string by a space.
> Surely this can be done with a one-liner?
A very long and hard to read one-liner, sure. TRANSFER the string
to an array of character (you'll have to do this in two places: the TSOURCE
operand to MERGE, and inside the MASK expression to MERGE), use
MERGE (the FSOURCE operand is, of course, just a space character),
then use TRANSFER again to get the result back into the form of a string.
Unless the above is *very* much faster (or you can prove the code
using it is a *very* critical bottle-neck) you should prefer the more
legible simple scalar loop.
do i = 1, len(string)
if(string(i:i) == '-') String(i:i) = ' '
end do
Of course, you *can* make that a one liner:
do i = 1, len(string); if(string(i:i) == '-') String(i:i) = ' '; end do
--
J. Giles
"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies." -- C. A. R. Hoare