by Carl Ranson >> Thu, 4 May 2000 21:23:48 GMT
Hi all.
I've had these two methods on the string primitive for ages. They've proven to be really useful.
for instance you can do things like...
var
s : String;
begin
s := 'This is a test string';
write s.before('test'); // "This is a "
write s.after('This '); // "is a test string"
s := 'Want to change this number (xxx) to something else';
write s.after("(").before(")"); // writes "xxx"
s := s.before("(") & "(" & "YYY" & ")" and s.after(")"); // changes xxx to YYY
end;
hope you find them helpful.
CR
before(delimeter : String) : String;
vars
index : Integer;begin
index := self.pos(delimeter,1);
if index = 0 then
return self;
else
return self[1:index-1];
endif;
end;
after(delimeter : String) : String;
vars
index : Integer;begin
index := self.pos(delimeter,1);
if index = 0 then
return null;
else
return self[index+delimeter.length:end];
endif;
end;