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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String find and replace 1

Status
Not open for further replies.

Steve688

IS-IT--Management
Oct 23, 2002
34
CA
I am trying to search a string for an errant space at the end of a name, and then replace the record with the name minus the space at the end. This will help in some record comparisons later down the line.

I'm pretty sure that I am missing only something small, Thanks in advance.
Code:
srcTC.open(sourcefile)
srcTC.edit()
	while not srcTC.eot()
             
     	  Fname = srcTC."FIRSTNAME"
   	  Fnsize = (Fname.size())  ;// reports the amount of characters in the Firstname field.
	  if subStr(Fname,1,Fnsize - 1 ) = " "  then
	     srcTC."FIRSTNAME" = subStr(Fname,1,Fnsize - 1)
	  else
	  endIf

  	  if srcTC."ADDRCORRECT" = "" then
	     srcTC."ADDRCORRECT" = "Y" 
	  else
	  endIf
	  if srcTC."CANCELCODE" = "DC" then
	     srcTC."CANCELCODE" = "D" 
	  else
	  endIf
	    status = "  Fixing source file"
	    srcTC.nextrecord()
	endWhile
	srcTC.close()
 
Is the space the last character in the field?

If so, you can just TRIM it.

srcTC."firstname"=rtrim(srcTC."firstname")

Although Paradox doesn't usually allow a trailing space to be stored in a field.

Even at that, your substr() (ie. start character 1 thru all characters EXCEPT the last one) statement is looking for all but the last character of 'firstname' to equal " ", which isn't likely to happen.

Tony McGuire
"It's not about having enough time. It's about priorities.
 
Hi Tony,

Yes, when they do occur, they are at the very end of the string. rTrim did the trick, Thanks! I didn't know about that function before.

Cheers!
-Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top