Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Delete text from a variable
Message
De
31/01/2013 15:03:21
 
 
À
30/01/2013 20:41:45
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01564785
Message ID:
01564883
Vues:
33
>I am trying to find out how to delete the first line of text from the
>text string in a memo field, no matter what characters are, in the
>line.


Depending on the original encoding, and whether or not the memo field is binary, it could contain unusual combinations of CHR(13) and CHR(10) characters. The most consistent results will come from letting Visual FoxPro parse the memo contents using ALINES(), then ignore that first row and reassemble the string. It's a little clunky, but it will always give you consistent results:
SET STEP ON

* Create the test table
CREATE TABLE foo ;
	(cMemo m NOCPTRANS)

* Insert various combinations of lines
INSERT INTO foo ;
            (cMemo) ;
    VALUES  ("This is line 1" + CHR(13) + ;
             "This is line 2" + CHR(10) + ;
             "This is line 3" + CHR(13) + CHR(10) + ;
             "This is line 4, the last line")

* Grab the lines
ALINES(laLines, foo.cMemo)

* Build the expression, skipping past the first line
* Note:  If there was only one line, the string will now be empty
lcNewMemo = SPACE(0)
FOR lnI = 2 TO ALEN(laLines,1)
    lcNewMemo = lcNewMemo + laLines[lnI] + CHR(13)
NEXT

* Update it back in the table
UPDATE foo ;
	SET cMemo = lcNewMemo
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform