Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

removing a character with replace - was: RE: [REBOL]

 [1/7] from: anton:lexicon at: 5-Nov-2002 12:24


Actually, Louis probably wants this: replace/all first x #"ÿ" "" replacing with an empty string, not an empty character. An empty character is ascii 0:
>> to-integer #""
== 0 which you can see escape-coded in the string below: "^@" Anton.

 [2/7] from: louisaturk:coxinet at: 4-Nov-2002 22:47


-- Unable to decode HTML file!! --

 [3/7] from: louisaturk:coxinet at: 4-Nov-2002 23:47


Anton, At 12:24 PM 11/5/2002 +1100, you wrote:
>Actually, Louis probably wants this: > > replace/all first x #"=FF" ""
Actually I first tried: replace/all "replace/all x "=FF" "" but since it didn't work (because of the square brackets I overlooked), I tried searching for characters instead of strings. You did not mean to put "first" in your example, right?
>replacing with an empty string, not an empty character. >An empty character is ascii 0: > > >> to-integer #"" > == 0 > >which you can see escape-coded in the string below: > > "^@"
Thanks for pointing this out; I certainly didn't know it. Louis

 [4/7] from: anton:lexicon at: 7-Nov-2002 1:33


Louis,
> >Actually, Louis probably wants this: > >
<<quoted lines omitted: 4>>
> tried searching for characters instead of strings. > You did not mean to put "first" in your example, right?
I did mean it. That's in the case where, for example: x: ["a string"] We needed to modify the first element in the block.
>> replace first x "a" "abc"
== "abc string"
>> x
== ["abc string"]
> >replacing with an empty string, not an empty character. > >An empty character is ascii 0:
<<quoted lines omitted: 7>>
> Thanks for pointing this out; I certainly didn't know it. > Louis
Neither did I. Anton.

 [5/7] from: louisaturk:coxinet at: 6-Nov-2002 16:35


At 01:33 AM 11/7/2002 +1100, you wrote:
>Louis, > > >Actually, Louis probably wants this:
<<quoted lines omitted: 16>>
> >> x > == ["abc string"]
I just tested again. At the console I get:
>> x: ["aaaaaaa string"]
== ["aaaaaaa string"]
>> replace/all x "a" "s"
== ["aaaaaaa string"]
>> x
== ["aaaaaaa string"]
>> replace/all first "a" "s" >> x: ["aaaaaaa string"]
== "sssssss string" That is just as you said. When I run it as a script: rebol [] x: ["aaaaaaa string"] replace/all first x "a" "s" It works also. However, this script doesn't work: rebol [] x: ["aaaaaaa string" "what is an apple good for"] foreach l x [ replace/all first l "a" "s" ] ** Script Error: replace expected target argument of type: series ** Near: replace/all first l "a" "s" But without first it works. What is happening? Louis

 [6/7] from: anton:lexicon at: 7-Nov-2002 12:50


You need to analyze, Louis! :) Break the problem down.
> I just tested again. At the console I get: > >> x: ["aaaaaaa string"]
<<quoted lines omitted: 6>>
> >> x: ["aaaaaaa string"] > == "sssssss string"
I don't believe you. :) That should be replace/all first x "a" "s" 'replace takes three arguments. I will use parentheses to see clearly the first argument to replace: replace/all (first x) "a" "s" The two lines of code above are equivalent. If you want to see what first x is, use probe: replace/all (probe first x) "a" "s" or probe first x replace/all first x "a" "s"
> However, this script doesn't work: > rebol []
<<quoted lines omitted: 6>>
> But without first it works. What is happening? > Louis
foreach creates the nice situation where, each iteration through the loop, 'l is set to: first x second x so you already have what you want. I recommend using ?? and 'probe again: foreach l x [ ?? l ; <---- here you can see the value of 'l probe first l ; <---- let's just see what we would get... replace/all l "a" "s" ?? l ; <---- here is the result ] Anton.

 [7/7] from: louisaturk:coxinet at: 6-Nov-2002 22:37


Anton, At 12:50 PM 11/7/2002 +1100, you wrote:
>You need to analyze, Louis! :) >Break the problem down.
<<quoted lines omitted: 12>>
>That should be > replace/all first x "a" "s"
Sorry, I probably copied a mistyped line. Actually, I'm not sure what I did. I stayed up too late trying to meet a deadline. It never pays off. My brain starts slipping out of gear when I get too sleepy. :>)
>'replace takes three arguments. >I will use parentheses to see clearly the
<<quoted lines omitted: 26>>
> second x >so you already have what you want.
Ok, this is what was confusing me. I remember now reading that foreach provided this feature.
>I recommend using ?? and 'probe again: > foreach l x [
<<quoted lines omitted: 4>>
> ] >Anton.
I didn't know about ?? It will be useful for debugging. Many thanks for explaining. Louis

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted