Find a Specific Character in a Field and Replace it with a Phrase

﹥>﹥吖頭↗ 提交于 2019-12-23 05:12:07

问题


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.



来源:https://stackoverflow.com/questions/14283400/find-a-specific-character-in-a-field-and-replace-it-with-a-phrase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!