Page 1 of 1

string::last

Posted: 3 Mar 2009 22:13
by Gildas Menier
Last (...) Returns the last Count characters of Source (according to help).

It seems that it rather returns the end of the string starting at the given position :

last("hello",1) returns "ello"

should return "o" ?

last("hello",string::length("hello")-1) ?

Regards

Gildas

Re: string::last

Posted: 24 Jun 2018 8:30
by CalmoSoft
Hello Gildas,

In the VIP 8.02 HTML help file there is:

Code: Select all

string::last/2->   last : (     string Source,     charCount Position)     -> string Last.   Retired: use fromPosition/2 instead
The next code works properly:

Code: Select all

pos := string::fromPosition("hello",string::length("hello")-1)
Greetings,
Gal Zsolt
(~ CalmoSoft ~)

Re: string::last

Posted: 25 Jun 2018 7:56
by Thomas Linder Puls
We noticed this problem at some time, and decided that both behaviors made sense. The documentation explained one thing and the behavior was the other. So to avoid problems for people that used the predicate we decided that we could not change the behavior and instead the predicate is now deprecated, replaced by these predicates:

Code: Select all

predicates     rear : (string Source, charCount Count) -> string Last.     % @short Return the last #Count characters of #Source.     % @example     % % All the statements below succeed:     % "d" = rear("abcd",1)<br>     % "" = rear("abcd",0)<br>     % "A" = rear("A",5)<br>     % "dart test " = rear("Standart test ",10)<br>     % "" = rear("",0)     % @end   predicates     fromPosition : (string Source, charCount Position) -> string Last.     tryFromPosition : (string Source, charCount Position) -> string Last determ.     % @short Return the last part of #Source from #Position     % @example     % % All the statements below succeed:     % "" = fromPosition("", 0)<br>     % "abcd" = fromPosition("abcd", 0)<br>     % "bcd" = fromPosition("abcd", 1)<br>     % "" = fromPosition("abcd", 4)<br>     % % An example below raises exception: string_exception::outOfBoundaries     % Last = fromPosition("abcd", 5)     % @exception fromPosition/2-> raises string_exception::outOfBoundaries     % if #Source contain less than #Position characters.     % @end
rear corresponds to the documentation of the old predicate. fromPosition corresponds to the behavior of the old predicate. But that obviously only help people that uses the new version.

Re: string::last

Posted: 25 Jun 2018 18:15
by CalmoSoft
Hello Thomas,

Thanks for your explanations.

Greetings,
Gal Zsolt
(~ CalmoSoft ~)