remove character from end of line if character exists?
[1/13] from: bry::itnisk::com at: 16-Jul-2003 12:27
I'm doing the following:
parsestring-length: length? parsestring
tempstring: at parsestring parsestring-length
if find tempstring "/" [
reverse parsestring
remove parsestring
reverse parsestring
]
this seems really inelegant. Anyone have a good solution?
[2/13] from: g:santilli:tiscalinet:it at: 16-Jul-2003 13:05
Hi bryan,
On Wednesday, July 16, 2003, 12:27:53 PM, you wrote:
b> this seems really inelegant. Anyone have a good solution?
if #"/" = last parsestring [
remove back tail parsestring
]
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r
[3/13] from: Christophe:Coussement:mil:be at: 16-Jul-2003 12:51
but even shorter:
;==> index keeps track of position where "/" is found
if index: find parsestring "/" [
remove index
]
==xtof
[4/13] from: Christophe:Coussement:mil:be at: 16-Jul-2003 12:39
if find tempstring "/" [
remove back tail parsestring
]
==xtof
[5/13] from: carl::cybercraft::co::nz at: 24-Dec-2003 22:23
On 16-Jul-03, bryan wrote:
> I'm doing the following:
> parsestring-length: length? parsestring
<<quoted lines omitted: 5>>
> ]
> this seems really inelegant. Anyone have a good solution?
This do what you want? ...
if "/" = tempstring: back tail parsestring [remove tempstring]
Hmmm - or even better...
remove find back tail parsestring "/"
Warning: Not extensively tested...
--
Carl Read
[6/13] from: ingo:2b1 at: 16-Jul-2003 13:53
Hi Bryan,
if #"/" = last parsestring [remove back tail parsestring]
Kind regards,
Ingo
bryan wrote:
[7/13] from: bry:itnisk at: 16-Jul-2003 14:00
Thanks.
[8/13] from: ptretter:charter at: 16-Jul-2003 8:10
Alot of good examples have been posted but what would be best suited to the
task would be 'trim if RT would allow the /with refinement to be used along
with /tail. Then you could simple do:
trim/tail/with tempstring "/"
Maybe this should be submitted as an enhancement.
Paul Tretter
[9/13] from: ingo:2b1 at: 16-Jul-2003 15:21
Hi Christophe,
Coussement Christophe wrote:
> but even shorter:
>
> ;==> index keeps track of position where "/" is found
> if index: find parsestring "/" [
> remove index
> ]
>
> ==xtof
Only this will remove the _first_occurrences_ of "/" from the string,
while, as I understand it, it should only be removed if it is actully
the _last_character_ in the string.
[10/13] from: Christophe:Coussement:mil:be at: 16-Jul-2003 15:27
Ingo:
You got a point ! I presume I was a little bit to fast ...
[11/13] from: antonr:iinet:au at: 17-Jul-2003 2:21
How about this:
foreach s ["" "/" "abc/" "/abc/"][
if #"/" = pick back tail s 1 [remove back tail s]
?? s
]
Handles if string is empty, too.
Anton.
[12/13] from: rotenca:telvia:it at: 16-Jul-2003 18:40
Another solution:
remove find back tail str #"/"
---
Ciao
Romano
[13/13] from: tomc:darkwing:uoregon at: 17-Jul-2003 0:01
token: "/"
if here: find/last parsestring token[clear here]
On Wed, 16 Jul 2003, bryan wrote:
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted