Board index » delphi » How can program a Rght function??

How can program a Rght function??

Hi there,

I programmed a Right function some time ago, but now when I upgraded my
program to Delphi 2.0 it gives me strange error. Has somebody else a
Right function (the last x characters of a string), a All function (put
20 characters in a string), SUB (characters x through y from a string)!!

Of can I use COPY like i used it in LEFT,

Thanks,

--
    \\\|///  
  \\  ~ ~  //      Delphi programming!!!
   (  @ @  )        BSYS Software Inc.
 oOOo (_) oOOo

 

Re:How can program a Rght function??


Hi,

The one I've been using is:

function RightStr(s: String; n: Integer): String;
{ Returns the last n chars of a string}

var
        i: Integer;

begin
        if n < 1 then
        Result := ''
   else if n >= Length(s) then
        Result := s
   else
   begin
        i := Length(s) - n + 1;
        Result := Copy(s, i, n)
   end;
end;

I don't doubt someone will come up with something far more elegant than
that but it works.

HTH

--
================================================
Ian Jennings                    i...@sys.uea.ac.uk
School of Information Systems
University of East Anglia
Norwich                             01603 592878
England                
     http://hector.sys.uea.ac.uk/~ij/welcome.htm
------------------------------------------------

Re:How can program a Rght function??


* In a message on 05-30-96, VAN HOESERLANDE EDDY said the following:

VHE> I programmed a Right function some time ago, but now when I

Quote
> upgraded my program to Delphi 2.0 it gives me strange error. Has
> somebody else a Right function (the last x characters of a string),
> a All function (put 20 characters in a string), SUB (characters x
> through y from a string)!!

Are you assuming that byte[0] is the length byte of the string?  In
v2.00 this may not always be true.

jim.sm...@lunatic.com  Written on May 31, 1996 at 03:54p.
.

-- SRW [Alpha/11]: SRW: Speed Read for Windows!

----
The Lunatic Fringe * Richardson, TX * 214-235-5288 * Home Of FringeNet

Other Threads