Home   Archive   Permalink



Removing a character from a string

@Nick:
    
I want to remove the character 's' from "https" in a url string: "https://...."
    
Can you help me, please?
Thanks in advance!


posted by:   Jma       21-May-2014/6:25:05-7:00



Hi Jma,
    
What have you tried already?
If you use Rebol3 then some help can be found http://www.rebol.com/r3/docs/functions/replace.html
    
replace https-url "https://" "http://"
    
If you use Rebol2 then replace doc is http://www.rebol.com/docs/words/wreplace.html
    
>> help url
Found these words:
     decode-url     function! Decode a URL into an object.
     to-url         function! [value]
     url!            datatype! url!
     url?            action! Returns TRUE for url values.
    
>> https-url: to-url "https://www.rebol.com"
== https://www.rebol.com
>> http-url: replace https-url "https://" "http://"
== http://www.rebol.com
>> type? http-url
== url!
>>
    
Does this answer your question?
Regards,
    
Arnold


posted by:   Arnold       21-May-2014/7:05:45-7:00



I want to remove a single character from a string.
If I have the string "rebol", how do I remove the character "o" so that the string becomes "rebl" ?


posted by:   Jma       21-May-2014/7:38:24-7:00



>> head remove find "rebol" "o"
== "rebl"

posted by:   Peter Wood       21-May-2014/8:30:51-7:00



Take a read of this - http://www.rebol.com/docs/core23/rebolcore-6.html
    
It should help you understand my answer,

posted by:   Peter Wood       21-May-2014/8:32:51-7:00



This also works:
    
x: "rebol"
replace x "o" ""

posted by:   Nick       21-May-2014/20:10:08-7:00



Quick note on this one -
    
x: "rebol"
replace x "o" ""
    
It will only replace the first "o". replace/all can be used to change them all.
eg
    
x: "rebolo"
replace x "o" ""
=> "rebl"

posted by:   John       26-May-2014/19:00:43-7:00



x: "rebolo"
replace/ALL x "o" ""
=> "rebl"

posted by:   Nick       27-May-2014/6:09:34-7:00