Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pascal substr equivalent

I was looking for a Pascal equivalent for (for example) the php's substr function, which works like this:

$new_string = substr('abcdef', 1, 3);  // returns 'bcd'

I've already found it, but I always take excessively long to do so, so I'm posting the answer for others like me to be able to easily find it.

like image 411
Michael Konečný Avatar asked Sep 03 '12 20:09

Michael Konečný


1 Answers

You can use the function copy. The syntax goes:

copy(string, start, length);

Strings in Pascal seem to be indexed starting from the 1, so the following:

s1 := 'abcdef';
s2 := copy(s1, 2, 3);

will result in s2 == 'bcd'.

Hope this helps someone.

like image 70
Michael Konečný Avatar answered Nov 14 '22 13:11

Michael Konečný