Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Need new UDF strreplace
Message
De
10/05/2007 09:29:51
 
 
À
09/05/2007 13:24:50
Mike Yearwood
Toronto, Ontario, Canada
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01223626
Message ID:
01224111
Vues:
28
>>>>>Thanks, but I don't think so. :) It's got to be positional. That would overwrite every occurance of that value throughout the string, no?
>>>>>
>>>>>Given a string with a specified delimiter
>>>>>
>>>>>ISA*00*00*ZZ*TEST^
>>>>>
>>>>>remove the ZZ and replace it with MY. It's in the 4th "field" position.
>>>>>
>>>>>Thanks!
>>>>
>>>>Hi Mike,
>>>>
>>>>Most well-formed EDI documents are (or can be) one long string, so I'm not sure what you are asking for is doable.
>>>>
>>>>If you break up the transactions into segments it might be possible, but I don't think there is a 'generic' solution. I would guess that you typically need to know what Loop/Segment you are dealing with.
>>>
>>>Yes, each segment would be treated as a "record". The ISA line has preset field "positions".
>>>
>>
>>When dealing with elements by position, I typically call ALINSE() to break up the document into segments, then ALINES() again on segments of interest (and ALINES() again if a need a sub-element).
>
>I've found I get the best performance by pulling a text file into a cursor and processing it with scan/replace.
>
>I'd have to use alines to grab the elements, replace one element and undo the alines back to the string before writing it back to the field.

Aah, and here I can give you this code:
*	This is the counterpart of VFP's ALINES() function.
*	It will return a string that has the elements of a ONE-DIMENSIONAL array (1st parm) on separate lines.
*	The routine uses the TRANSFORM() function for the conversion.
*	Accepts an optional 2nd parameter that's used as 2nd parameter for the TRANSFORM() function.
*	Pass True as 3rd parameter if you want the lines to be without leading and trailing spaces.
*	Pass True as 4th parameter if you want to exclude empty elements.
*	Usage:
*		lcMultiLineText = AlinesX( @aArray, cFormatCodes )

FUNCTION aLinesX
lparameters taArray, tcFormatCodes, tlTrim, tlNotIfEmpty
local lcResult, lnCount, lcFormatCodes, lcLine

external array taArray

lcFormatCodes = iif( pcount() > 1, m.tcFormatCodes, '' )
lcResult      = ""

for lnCount = 1 to alen( taArray, 1 )
	lcLine = transform( taArray[ m.lnCount ], m.lcFormatCodes )	&& Using taArray[x,1] gave weird results. Must be a VFP-quirck!
	if m.tlTrim
		lcLine = alltrim( m.lcLine )
	endif
	if not m.tlNotIfEmpty or not empty( m.lcLine )
		lcResult = m.lcResult + chr(13) + chr(10) + m.lcLine
	endif
next

lcResult = substr( m.lcResult, 3 )

RETURN m.lcResult
Eventually you modify the code and parameterlist to use another delimiter instead of the default chr(13)+chr(10).
Groet,
Peter de Valença

Constructive frustration is the breeding ground of genius.
If there’s no willingness to moderate for the sake of good debate, then I have no willingness to debate at all.
Let's develop superb standards that will end the holy wars.
"There are three types of people: Alphas and Betas", said the beta decisively.
If you find this message rude or offensive or stupid, please take a step away from the keyboard and try to think calmly about an eventual a possible alternative explanation of my message.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform