bassmo Posted March 12, 2012 Share Posted March 12, 2012 Hi all, I have a rather annoying problem. I need to be able to run a replace on a string. In itself obviously not a problem. However I only need to replace the occurrence of the string when it is at the start of the string. Example: Need to replace Apple with Orange: AppleBananaPeach to become OrangeBananaPeach ApplePearPlumApple to become OrangePearPlumApple BananaApple to remain BananaApple All strings are a single "word", no spaces. The thought occurs to me to place a marker at the start. Something along the lines of: |ApplePearPlumApple -> Replace |Apple with Orange -> OrangePearPlumApple Any idea if I can do this? Many thanks in advance. Bassmo / Jon Quote Link to comment Share on other sites More sharing options...
bassmo Posted March 12, 2012 Author Share Posted March 12, 2012 Actually not tricky - just done it myself....sorry update testtable set myfield = replace(concat('|',myfield,'|apple','orange'); Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted March 12, 2012 Share Posted March 12, 2012 Or if you only want to show a different word without changing the data in the table you could use this, handy for masking the start of sensetive information, such as card no's and the like SELECT REPLACE((SELECT `text` FROM table where left(`text`, Length('WordToReplace')) = 'WordToReplace'), 'WordToReplace', 'NewWord') Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.