Slicing, like Python can do.
Slicing, like Python can do.
Sub-arrays:
mySubArray := myArray[3..5];
String manipulation:
//removes first and last character, useful for removing parens or brackets
function UnwrapString(const value: string): string;
begin
result := value[2..-1];
end;
function StripFileExt(const filename: string): string;
var
ext: string;
begin
ext := ExtractFileExt(filename);
if ext = '' then
result := filename
else result := filename[..-length(ext)];
end;
And so on. There's all sorts of useful things you can do with slicing.
Sub-arrays:
mySubArray := myArray[3..5];
String manipulation:
//removes first and last character, useful for removing parens or brackets
function UnwrapString(const value: string): string;
begin
result := value[2..-1];
end;
function StripFileExt(const filename: string): string;
var
ext: string;
begin
ext := ExtractFileExt(filename);
if ext = '' then
result := filename
else result := filename[..-length(ext)];
end;
And so on. There's all sorts of useful things you can do with slicing.
This looks like some syntactic sugar around Copy(), right?
ReplyDeleteIt could definitely be implemented that way... unless they went with some version of the full Python implementation, which takes an optional third parameter: the step size. Copy() can't emulate that. But the two-parameter version could easily be implemented on top of Copy().
ReplyDelete