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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Russell LibbyConnect With a Mentor Software 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
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
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
All Courses

From novice to tech pro — start learning today.