Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Odd string replacement: STRTRAN but with embedded spaces
Message
From
14/11/2006 10:22:39
 
 
To
13/11/2006 18:26:27
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01169359
Message ID:
01169467
Views:
9
Here's my attempt:
LOCAL lcString, lcUPC
lcString = "Small Widget (1 12345 12345 1)"
lcUPC = "112345123451"

lcRemoved = RemoveUPC(lcString,lcUPC)
CLEAR
?lcString
?lcRemoved

FUNCTION RemoveUPC
LPARAMETERS pcString,pcUPC
LOCAL lnNdx, lcRemoved, lnPos, lnUPC, llFound
lcRemoved = pcString
lnNdx = ATC(pcUPC,pcString)
IF lnNdx > 0
	lcRemoved = STUFF(pcString,lnNdx,LEN(pcUPC),"")
ELSE
	llFound = .F.
	FOR lnNdx=1 TO LEN(pcString)
		IF SUBSTR(pcString,lnNdx,1) = LEFT(pcUPC,1)
			lnPos = lnNdx
			lnUPC = 1
			DO WHILE lnUPC<=LEN(pcUPC) .AND. SUBSTR(pcString,lnPos,1) = SUBSTR(pcUPC,lnUPC,1)
				lnUPC = lnUPC + 1
				IF lnUPC > LEN(pcUPC)
					llFound = .T.
					EXIT
				ENDIF
				lnPos = lnPos + 1
				DO WHILE SUBSTR(pcString,lnPos,1) = " "   && Check for embedded spaces -- skip past
					lnPos = lnPos + 1
				ENDDO
			ENDDO
		ENDIF
		IF llFound
			lcRemoved = STUFF(pcString,lnNdx,lnPos-lnNdx+1,"")
			EXIT
		ENDIF
	ENDFOR
ENDIF
RETURN lcRemoved
ENDFUNC
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform