get 3 character from left

Hi...
does anybody knows how I can get the first 3 character from left of a variable .?

Thanks ^^
allie910Asked:
Who is Participating?
 
Russell LibbySoftware Engineer, Advisory Commented:

result:=Copy(variable, 1, 3)


Regards,
Russell
0
 
TheLeaderCommented:
is this variable string !?
ex:
S,T : String;
T := Copy (Length(S)-3,Length(S))
0
 
TheLeaderCommented:
sorry i thought it from right :p
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
TheLeaderCommented:
you can use as "rllibby"
or if you know about this
S : String;
s[1] :=  "1st char"
S[2] := "2nd char"
S[3] := "3rd char"
 and so on

hope it helped ...
0
 
sftwengCommented:
Be careful using S[i] rather than Copy - there's trouble if I > Length(s). rllibby's approach is safer.
0
 
Russell LibbySoftware Engineer, Advisory Commented:

TheLeader,

You might want to include the check for:

if (length(s) >= required_length) then
begin
  ... // access s[index], ie s[1], s[2], s[3] ...
end;

Just for completness in your example....

Kindest regards,
Russell



0
 
TheLeaderCommented:
yah i know, he must check the length first ofcourse
but i wanted to show him another way.

by the way "rllibby" I didn't see your post til I submit my first comment.
anyway, I get it in reverse :p
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.