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

How to remove text in a field

Status
Not open for further replies.

alisaif

ISP
Apr 6, 2013
418
AE
Hi,

In a table I have a lot of records for eg.,

CYAN1MX
GREEN1MX
YELLOW1MX
etc.
I want to remove MX. How it is possible?

Thanks

Saif
 
You can do that on your own, really.

I'll come back later and answer that, but you really are experienced enough and have had enough answers about string functons, UPDATEs and REPLACEs, that you can do this on your own and don't need to come here with such questions. Just remember in a table fields have a fixed length, the right 2 characters are most often after the word stored, as you normally store textual data left aligned, so you can't test for RIGHT(field,2)="MX". Hint: you first have to trim away spaces.

Bye, Olaf.
 
Thanks for the reply,

What about if it is :

MAGENTAMX1
MAGENTAMX2
REDMX2A
etc.

Saif
 
complexer, you'll need the position of the MX, you can get it with AT()

Bye, Olaf.
 
If you have many more cases, it could also get simpler checking against a list of allowed colors and determine and remove everything else as junk. eg set fields to 'MAGENTA', if 'MAGENTA' $ field, etc.

Bye, Olaf.
 
Saif, in a question like this, you've really got to be precise about what you want to do. In your first post, it's not clear whether you want to remove any occurrence of the letters MX, regardless of where they appear in the string, or whether you want to remove the last two letters of the string.

Apart from that, I agree with the general tone of Olaf's reply. This is not to discourage you from asking questions here. But this is the sort of thing that you should be able to work out for yourself by perusing the Help file. There are no special techniques invovled.

And never be afraid to resort to good old trail and error.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
>trial and error.

Indeed, that means working on a copy, obviously.

You can get surprising results, even if you think things through, so a copy is important to be able to get back to the initial situation. Things like this are not working by first solving the easiest case and then step forward, if you are confronted with many sepcific cases you turn the problem around and focus on the net data you want, not on the junk you want to get rid of.

Bye, Olaf.
 
I did like this:

mRc = 'MAGENTAMX2'
mRc = STRTRAN(mRc, 'MX', '')

Saif
 
Yes, that's exactly right. But the point is that you were able to find the answer yourself, presumably by looking at the string-handling function listed in the Help file.

By the way, even this solution is not strictly correct. That's because you did not specify how many instances of the substring ("MX") you want to remove. You solution will only work if the string only ever contains one instance, or if it contains multiple instances and you want to remove them all. Obviously, this isn't an issue in this case, but I hope you can see what I mean about defining the problem in precise terms.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Also, there are NUMEROUS threads here that address issues exactly like this.

And, like Olaf says, test with a copy. Or even better in simple cases, use the Command window to test.

mmerlinn


Poor people do not hire employees. If you soak the rich, who are you going to work for?

"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Raymond
 
I would for example never have guessed you want to keep the number 1,2,2A

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top