Paradox Community

Items in pnews.paradox-programming

Subject:Quick and Dirty Search and Replace
Date:Fri, 4 May 2018 20:30:54 +1000
From:Robert MacMillan <macfam@bigpond.net.au>
Newsgroups:pnews.paradox-programming
Over the years there have been various bits of code offered for this and 
apparently Rick Kelly had something but that is no longer available.

So my interest in this is getting rid of the "'" in Horse Names or 
anything else that causes problems like "(NZ)". So names that can be 
"She's Beautiful" or "Mr'Oleary" or Look'n'Good. as examples.

So the quick and dirty code that I am currently using is:-

if tc.Name.search("'")>0
        	Then 	
             tc.Name.Breakapart(atStr, "'")
             s=""
             For k from 1 to atStr.size()
                	s=s+atStr[k]
             Endfor
       	    tc.HName=s
          Else tc.HName=tc.Name
Endif

Obviously this works absolutely perfectly except for two cases and that 
is where the Breakapart String being searched for is the entire end of 
the string or the entire beginning of the string. The extension is it 
can also be used as a "Search and Replace" by forming the new string by, 
lets assume that one wants the "'" to be replaced by "you are 
beautiful". If the substring is at the beginning I can add a test for 
the position of the first instance of the substring also being the first 
character of the string - not demonstrated here because it never occurs 
in horse names.

s=""
For k from 1 to atStr.size()
                	s=s+"you are beautiful"+atStr[k]
Endfor

So now turning it over to the brains trust. Where I have got to so far 
is very fast and very efficient although rather less elegant than other 
solutions that have been posted previously. I can see how to deal with 
the first part of the entire string being identifiable but I cannot see 
how to overcome the situation where the characters in a string at the 
end are those that we want to replace and there are other instances 
within the string because the array will not identify that there is 
another replacement required.

I know this looks very simple compared to the other solutions that have 
been offered but it works and it is simple to code and is very fast.

Obviously one can code passing several different strings being searched 
and replaced and dealing with them sequentially but I still can not see 
how to deal with the case of one of the strings to be replaced being at 
the end of the string being searched.

Need help from the brains trust but for what I want where I want to get 
rid of for example "(NZ)" this works well.




Copyright © 2004 thedbcommunity.com