Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Databas text field

Status
Not open for further replies.

Phil Thoms

Programmer
Oct 31, 2005
245
GB
I have a field which is 65 characters in length and contains codes in brackets as follows:- (A), (B), (C) and so on.
These can appear in any part of the field. Is there a quick way of deleting these codes. I would normally do it manually but there are over 2000 records.



 
My FP 2.6 is a little =rusty but this should work.

Code:
USE DBF
GOTO TOP
SCAN ALL
	lcString = ALLTRIM(FIELD)
	lcString = Parse(lcString , "(" , '')
	lcString = Parse(lcString , ")" , '')
	..... any other char you want stripped out 

	REPLACE FIELD WITH lcString

ENDSCAN

CLOSE DATA

FUNCTION Parse
PARAMETER pcString, pcChar, pcWith
SET STEP ON
llDoit = .t.
DO WHILE llDoIt = .T.
	lnLen = LEN(pcString)
        lnLoc = AT(pcChar,pcString)
	DO case
	CASE lnLen = 0
		llDoIt = .F.
	CASE lnLoc = 0
		llDoIt = .F.
	CASE lnLoc = 1
		pcString = SUBSTR(pcString,2)
	CASE lnLoc > 0
		lcFst = SUBSTR(pcString,1,lnLoc-1) + pcWith + SUBSTR(pcString,lnLoc+1)
	ENDCASE
ENDDO
RETURN pcString


David W. Grewe Dave
 
philthoms,
not fully clear your wish.
Show examples old and new fields.
Meanwhile see strtran() or stuff().
Tesar
 
Sorry Forgot to change a Memvar name

lcFst = SUBSTR(pcString,1,lnLoc-1) + pcWith + SUBSTR(pcString,lnLoc+1)

should be

lcString = SUBSTR(pcString,1,lnLoc-1) + pcWith + SUBSTR(pcString,lnLoc+1)


David W. Grewe Dave
 
Tesar
My Memory is getting older then version 2.6, Did Strtran() and Stuff() exist in version 2.6 ???



David W. Grewe Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top