David James wrote:
There may well already be a provided routine to do this (return the last i characters of a string), and if there is, I'd be grateful for a pointer to it, but even so I think I'd still like to be able to write similar procedures/functions.
The functions `Copy' and `SubStr', when called with 2 parameters s and i, return all the characters of s starting from the i'th. The difference is that `SubStr' causes a runtime error when i < 1 or i > Length (s), while `Copy' returns the empty string then.
So, to get the last i characters of s, you can use `Copy (s, Length (s) - i + 1)', or if you want to accept i > Length (s) here and get the whole string then, you could do `Copy (s, Max (1, Length (s) - i + 1))'.
Peter Gerwinski wrote:
- In this example we are mixing Extended Pascal modules with UCSD (Borland) Pascal units. EP wants `import' instead of `uses'.
While GPC accepts all this, it is maybe better to stick to one flavour of modularized Pascal programming which means either EP-style modules or UCSD-style unit, but not a mixture.
He did `uses gpc;' which is correct since gpc.pas is indeed a unit (and is not available as a module). So I think it's alright to mix this unit with modules.
Frank