1. Replacing

What library routine do I use to change:

/home/irv/storm%20clouds.jpg 
-- to 
/home/irv/storm clouds.jpg 

I tried find_replace("%20",fname," "), which doesn't change the filename at all.

new topic     » topic index » view message » categorize

2. Re: Replacing

irv said...

What library routine do I use to change:

/home/irv/storm%20clouds.jpg 
-- to 
/home/irv/storm clouds.jpg 

I tried find_replace("%20",fname," "), which doesn't change the filename at all.

match_replace("%20",fname," ")

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

3. Re: Replacing

Thanks! I was using replace_all, and see that it got deprecated. match_replace works.

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

4. Re: Replacing

jimcbrown said...
irv said...

I tried find_replace("%20",fname," "), which doesn't change the filename at all.

match_replace("%20",fname," ")

find_replace, match_replace work just like find and match. Thus

find_replace("%20", "John Doe", "Jim Doe") 

is actually looking for {{'%','2','0'}} inside of {'J','o','h','n',...}

Also, these methods do not replace inplace. You must accept the result:

filename = match_replace("%20", filename, " ") 

You could use find_replace in a synario such as:

find_replace("Jim", { "John", "Jack", "Joe", "Jim", "Jane" }, "Jeremy") 

Jeremy

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

5. Re: Replacing

irv said...

Thanks! I was using replace_all, and see that it got deprecated. match_replace works.

replace_all() was deprecated in favor of match_replace(). Ironic?

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

6. Re: Replacing

jimcbrown said...

replace_all() was deprecated in favor of match_replace(). Ironic?

match_replace does everything replace_all did, but a bit more.

man:std_search#match_replace, i.e. replaces all by default, but you can use it to replace up to X matches. It also fits our naming scheme. find, match, find_replace, match_replace, ...

Jeremy

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

7. Re: Replacing

irv said...

What library routine do I use to change:

/home/irv/storm%20clouds.jpg 
-- to 
/home/irv/storm clouds.jpg 

I tried find_replace("%20",fname," "), which doesn't change the filename at all.

there is also include std/net/url.e

encode/decode for this type of conversion.

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

Search



Quick Links

User menu

Not signed in.

Misc Menu