Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Simple string manipulation problem
Message
 
 
À
06/08/2001 13:07:46
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00540244
Message ID:
00540257
Vues:
21
James,

This is certainly helpful, but you consider only + in index expression. There could be other symbols used, for instance, () If it's a filter, the number of symbols increased, because they could be < > #, etc.

>Nadya,
>
>This is the function we use,
>
>
********************************************************************************
>FUNCTION ADDALIAS( tcExpr, tcAlias )
>********************************************************************************
>*
>*   OVERVIEW:  Adds the alias name to a list of field names contained in an
>*	       index expression so that alias and field names are paired, and
>*	       returns the amended expression.
>*
>*   EXAMPLE:   ADDALIAS( "sys_code + pipe", "ansurvey" ) ->
>*			"ansurvey.sys_code + ansurvey.pipe"
>*
>*   PARAMETERS:	tcExpr	The index expression to which alias is to be added
>*			tcAlias		The alias name to be added.
>*
>*   RETURN:	(C)	The index expression with alias name added to each field
>*			name in the expression.
>*
>LOCAL lnNumFields, lcExpr, lcThisField, lnThisFieldPosition, lnI, lcAliasedExpr
>
>DO WHILE " " $ tcExpr
>   tcExpr = STRTRAN( tcExpr, " ", "" )
>ENDDO
>
>*   Get the number of fields in the expression
>lnNumFields = OCCURS( '+', tcExpr ) + 1
>
>*   This variable will be used to hold the amended expression with alias name
>*   added to each field in the expression.
>lcAliasedExpr = ''
>
>*   NOTE: There is no testing to determine whether the field is actually in the
>*   specified table.  Testing if wanted should be added here.
>FOR lnI = 1 TO lnNumFields
>
>    IF lnI = lnNumFields
>        lcThisField = lcExpr
>    ELSE
>        lcThisField = LEFT( lcExpr, AT( '+', lcExpr ) - 1 )
>    ENDIF
>
>    IF OCCURS( '( ', lcThisField ) > 0
>        lnThisFieldPosition = ;
>            AT( '( ', lcThisField, OCCURS( '( ', lcThisField ) ) + 1
>    ELSE
>        lnThisFieldPosition = 0
>    ENDIF
>
>    lcAliasedExpr = ;
>        lcAliasedExpr + IIF( !EMPTY( lcAliasedExpr ), '+', '' ) + ;
>            STUFF( lcThisField, lnThisFieldPosition, 0, tcAlias + '.' )
>
>    lcExpr = SUBSTR( lcExpr, AT( '+', lcExpr ) + 1 )
>
>NEXT
>
>RETURN lcAliasedExpr
>
>ENDFUNC && ADDALIAS() 
>
>Hope this helps,
>
>Regards
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform