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
-
- VIP Member
- Posts: 73
- Joined: 17 Oct 2006 5:49
Re: string::last
Hello Gildas,
In the VIP 8.02 HTML help file there is:
The next code works properly:
Greetings,
Gal Zsolt
(~ CalmoSoft ~)
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
Code: Select all
pos := string::fromPosition("hello",string::length("hello")-1)
Gal Zsolt
(~ CalmoSoft ~)
-
- VIP Member
- Posts: 1466
- Joined: 28 Feb 2000 0:01
Re: string::last
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:
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.
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
Regards Thomas Linder Puls
PDC
PDC
-
- VIP Member
- Posts: 73
- Joined: 17 Oct 2006 5:49
Re: string::last
Hello Thomas,
Thanks for your explanations.
Greetings,
Gal Zsolt
(~ CalmoSoft ~)
Thanks for your explanations.
Greetings,
Gal Zsolt
(~ CalmoSoft ~)