Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
My file to string does nor have CR characters
Message
De
29/10/2014 12:41:42
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01609739
Message ID:
01610116
Vues:
35
The error comes about because narry I forgot that it is a column in a table. The "m." prefix would only work if you had a memory variable with the name. Updated the program:
#DEFINE _CR_   CHR(13)
#DEFINE _LF_    CHR(10)
#DEFINE _NL_   _CR_+_LF_
SELECT eit
SCAN
    cBuf = CHRTRAN(ALLTRIM(narry),_LF_,_CR_)
    DO WHILE _CR_+_CR_ $ m.cBuf
        narry = STRTRAN(m.cBuf,_CR_+_CR_,_CR_)
    ENDDO
    cBuf = STRTRAN(m.cBuf_CR_,_NL_)
    = strtofile(cBuf, 'c:\colineit.txt', 1)
    = strtofile( _NL_+REPLICATE('-',20)+_NL_,'c:\colineit.txt',1)
ENDSCAN
to get rid of the extraneous lines with dashes, we could modify thusly:
#DEFINE _CR_   CHR(13)
#DEFINE _LF_    CHR(10)
#DEFINE _NL_   _CR_+_LF_
SELECT eit
SCAN
    cBuf = CHRTRAN(ALLTRIM(narry),_LF_,_CR_)
    DO WHILE _CR_+_CR_ $ m.cBuf
        narry = STRTRAN(m.cBuf,_CR_+_CR_,_CR_)
    ENDDO
    cBuf = RTRIM(m.cBuf,_CR_," ")
    cBuf = STRTRAN(m.cBuf_CR_,_NL_)
    = strtofile(cBuf+_NL_, 'c:\colineit.txt', 1)
ENDSCAN
The effect of all those CHRTRAN() and STRTRAN() calls is to basically translate the instances of carriage return and linefeed and turning them into newline sequences of carriage return followed by newline. I'm also reducing repeated newlines into single ones (basically removing "blank" lines). Also at the end when appending string to file, I'm making sure that there is a newline at the end.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform