WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: pamsniffer on April 25, 2017, 06:03:51 AM

Title: add word to string on eache line
Post by: pamsniffer on April 25, 2017, 06:03:51 AM



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.






Title: Re: add word to string on eache line
Post by: td on April 25, 2017, 07:10:07 AM
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.
Title: Re: add word to string on eache line
Post by: pamsniffer on April 25, 2017, 11:33:02 AM
thx

that was the trick