1. find_replace() not working

include std/search.e  -- find_replace() 
 
   
  sequence badbadchars = {"/"} 
  sequence title = "SCRs, SCR/Diode - Arrays" 
  sequence filteredtitle, junk 
   
  with trace 
   
  trace(1) 
   
  filteredtitle = title 
  for badloop = 1 to length(badbadchars) do 
    junk = badbadchars[badloop] 
    filteredtitle = find_replace(badbadchars[badloop],filteredtitle,"-",0) 
  end for 
  puts(1,filteredtitle&"\n") 
   
  trace(1) 


The badbadchar in filteredtitle is never replaced. Why?

also doesn't work if i use:

filteredtitle = find_replace({badbadchars[badloop]},filteredtitle,"-",0) 


useless

new topic     » topic index » view message » categorize

2. Re: find_replace() not working

useless said...
include std/search.e  -- find_replace() 
 
   
  sequence badbadchars = {"/"} 
  sequence title = "SCRs, SCR/Diode - Arrays" 
  sequence filteredtitle, junk 
   
  with trace 
   
  trace(1) 
   
  filteredtitle = title 
  for badloop = 1 to length(badbadchars) do 
    junk = badbadchars[badloop] 
    filteredtitle = find_replace(badbadchars[badloop],filteredtitle,"-",0) 
  end for 
  puts(1,filteredtitle&"\n") 
   
  trace(1) 


The badbadchar in filteredtitle is never replaced. Why?

also doesn't work if i use:

filteredtitle = find_replace({badbadchars[badloop]},filteredtitle,"-",0) 


useless

Its not working how you expected it to because you are trying to find the STRING "/" inside filteredtitle but that variable doesn't contain that string. It does however contain the character '/'.

Try this ...

include std/search.e  -- find_replace() 
 
   
  sequence badbadchars = "/" 
  sequence title = "SCRs, SCR/Diode - Arrays" 
  sequence filteredtitle 
   
  filteredtitle = title 
  for badloop = 1 to length(badbadchars) do 
    filteredtitle = find_replace(badbadchars[badloop],filteredtitle,'-',0) 
  end for 
  puts(1,filteredtitle&"\n") 
   
new topic     » goto parent     » topic index » view message » categorize

3. Re: find_replace() not working

DerekParnell said...
useless said...
include std/search.e  -- find_replace() 
 
   
  sequence badbadchars = {"/"} 
  sequence title = "SCRs, SCR/Diode - Arrays" 
  sequence filteredtitle, junk 
   
  with trace 
   
  trace(1) 
   
  filteredtitle = title 
  for badloop = 1 to length(badbadchars) do 
    junk = badbadchars[badloop] 
    filteredtitle = find_replace(badbadchars[badloop],filteredtitle,"-",0) 
  end for 
  puts(1,filteredtitle&"\n") 
   
  trace(1) 


The badbadchar in filteredtitle is never replaced. Why?

also doesn't work if i use:

filteredtitle = find_replace({badbadchars[badloop]},filteredtitle,"-",0) 


useless

Its not working how you expected it to because you are trying to find the STRING "/" inside filteredtitle but that variable doesn't contain that string. It does however contain the character '/'.

Try this ...

include std/search.e  -- find_replace() 
 
   
  sequence badbadchars = "/" 
  sequence title = "SCRs, SCR/Diode - Arrays" 
  sequence filteredtitle 
   
  filteredtitle = title 
  for badloop = 1 to length(badbadchars) do 
    filteredtitle = find_replace(badbadchars[badloop],filteredtitle,'-',0) 
  end for 
  puts(1,filteredtitle&"\n") 
   


You did not notice the first block of eucode i did first is just what you said to try. That's what didn't work first. What didn't work second was the the second block of eucode i gave. You responded to the second block of code, telling me to try the first block, which already didn't work.

I had also tried:

sequence badbadchars = {'/'} 


useless

new topic     » goto parent     » topic index » view message » categorize

4. Re: find_replace() not working

useless said...

You did not notice the first block of eucode i did first is just what you said to try. That's what didn't work first. What didn't work second was the the second block of eucode i gave. You responded to the second block of code, telling me to try the first block, which already didn't work.
I had also tried:

sequence badbadchars = {'/'} 

find_replace() literally uses find() to search for the needle you pass. So the correct needle to pass here is '/'. But it also simply replaces the element it finds with whatever you pass. So in this case, you should also be passing an integer '='. You're using find_replace() the way that match_replace() works.

Matt

new topic     » goto parent     » topic index » view message » categorize

5. Re: find_replace() not working

Kat said...


You did not notice the first block of eucode i did first is just what you said to try. That's what didn't work first. What didn't work second was the the second block of eucode i gave. You responded to the second block of code, telling me to try the first block, which already didn't work.

I had also tried:

sequence badbadchars = {'/'} 


useless

I most heartily disagree with your assertion, Ms Smith.

I did notice your first example. In fact, I copied it verbatim to my own system and ran the code, and I concur that it indeed does fail. My first attempt at getting it to work was to replace the line

sequence badbadchars = {"/"}  


with

sequence badbadchars = {'/'}  


because I noticed that your code was using a string rather than a character, and also noticing that in the title data there was the character '/', I made the assumption that you were trying to find the character '/' in the title data.

I then reran the code and it failed at a different point. It was now saying that there was a sequence embedded in the text. At which point I slapped my forehead (metaphorically) and saw the data that your code was using to replace the '/' character with. I realized that the code was now replacing the character '/' (an atom) with the string "-" (a sequence). So I again threw caution to the wind and made another assumption ... that you were trying to replace the '/' character with the '-' character and not with the "-" string.

So I replaced the line

filteredtitle = find_replace(badbadchars[badloop],filteredtitle,"-",0) 


with

filteredtitle = find_replace(badbadchars[badloop],filteredtitle,'-',0) 


and now it was working. However, before posting my response to your original questions, I tempted fate by cleaning up the code by removing the tracing paraphernalia and instead of using {'/'} I simply used "/" as the list of characters to search for.

So in conclusion, I believe that I addressed all your concerns and examples accurately and furthermore, I present a working and tidier code sample.



Yours sincerely,
Derek.

new topic     » goto parent     » topic index » view message » categorize

6. Re: find_replace() not working


Sorry Derek, Matt, i am just accustomed to doing this:

sequence badbadchars = {"*","?","\\",":",";","\'","\"","<",">","/"} 
 
  filteredtitle = title 
  for badloop = 1 to length(badbadchars) do 
    place = match(badbadchars[badloop],filteredtitle) 
    while place do 
      filteredtitle = filteredtitle[1..place-1] & "-" & filteredtitle[place+1..$] 
      place = match(badbadchars[badloop],filteredtitle) 
    end while 
  end for 
  puts(1,filteredtitle&"\n") 
 

and it just works. I didn't know there was a match_find(). What i wanted to do was more like:

filteredtitle = replace_all(badbadchars,title,"-") 


but that didn't seem to be happening. Throwing together the lines above was faster than finding my 3.11 replace routine. I should take a minute and drag all my older code to this computer.

useless

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu