add word to string on eache line

Started by pamsniffer, April 25, 2017, 06:03:51 AM

Previous topic - Next topic

pamsniffer




Hi,

How can i add to a string at the end of the string a extra a word

the code
cr=num2char(13)
lf=num2char(10)

sss="test"

string="aaaaaaaaaaaaaaa%cr%%lf%
            aaaaaaaaaaaaaaaa%cr%%lf%
            aaaaaaaaaaaaaaaa%cr%%lf%"

   sss=strcat("  ","- ",sss,"  "," ",@CRLF)
      record1 = StrReplace(record1,@CRLF,sss)


the output:

test
aaaaaaaaaaaaa test
aaaaaaaaaaaaa test


but the output must be:
aaaaaaaaaaaaa test
aaaaaaaaaaaaa test

What I am doing wrong.







td

The most obvious answer would be that you have a leading carriage-return plus line-feed in your "record1" variable.  If this is the case, you need to do something like the following before you perform a your StrReplace:

Code (winbatch) Select
while 1
   record1 = StrTrim(record1, 1)
   nPos = StrScan(record1, @Crlf, 1, @Fwdscan)
   if nPos == 1 then record1 = StrSub(record1, 3, -1)
   else break
endwhile


Of course, it could also be that you have an extra carriage-return plus line-feed at the end of a record.  If that is the case, you may be better off simply removing all duplicate carriage-return plus line-feeds.  It would depend on your goals.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

pamsniffer