-->

Find a Specific Character in a Field and Replace i

2019-06-12 05:51发布

问题:

I've been searching around the internet for an answer to this question for a few hours and I'm not able to find anything. My experience with FoxPro is quite limited. This will probably be 2 questions in one.

First question: I have a list of items and some of these items may contain a comma which is not allowed in the program I'm transferring the data to.

I basically need sort of a statement like this:

REPLACE ALL Field1 with STRTRAN(field1, "," , "<break time='250ms' />"

Is something like that going to accomplish what I need?

Second Question: I have 5 separate fields that I need the data from to be moved into a new field. Something like this.

Field1: October Field2: 21 Field3: 2013 Field4: 5:00 Field5: PM

FinalField Thank you for your email, your appointment is scheduled for [Field1] [Field2] [Field3] at [Field4] [Field5].

This will be for thousands of records, so I'd like to formulate a statement that would replace them all at once.

REPLACE ALL FinalField with STRTRAN(

After that I'm not sure what format it needs to be within the parenthesis to properly replace the field with what I need. Thank you for your help in advance.

回答1:

First question: What you've written will replace each occurrence of a comma with "<break time='250ms' />". Not sure that's what you're after. To simply remove all commas:

REPLACE ALL field1 WITH STRTRAN(field1, [,], [])

will do it. I like to use the [ ] characters as string delimiters when I'm dealing with commas, quotation marks, etc. - for clarity.

Take a look at the TEXTMERGE() function for the answer to your second question.



回答2:

For your second question, you can just write an expression like:

REPLACE ALL FinalField WITH ;
  "Thank you for your email, your appointment is scheduled for " + ;
  ALLTIRIM(Field1) + " " + TRANSFORM(Field2) + ;
  TRANSFORM(Field3) + " at " + ;
  ALLTRIM(Field4) + ALLTRIM(Field5) + "."

This assumes that Field1, Field4 and Field5 are character and Field2 and Field3 are numeric. If that's not so, you'll have to adjust them.

If you're doing a one-time export to another application, you might find it easier to write a SQL query to put all the data into the format you want and then export the cursor that query generates.