function ContainsBeforeEnd(const str, substr: string): Boolean;
var
P: Integer;
begin
P := Pos(substr, str);
if P = 0 then
// substr not found at all
Result := False
else
// found, now check whether substr is at the end of str
Result := P + Length(substr) - 1 <> Length(str);
end;
function ContainsBeforeEnd(const str, substr: string): Boolean;
begin
Result := not (Pos(subStr,Str) in [0,Length(str)-Length(subStr)+1]);
end;
function ContainsBeforeEnd(const str, substr: string): Boolean;
begin // Note, string helpers returns results based on zero based strings
Result := (Length(str) > Length(subStr) and
(str.IndexOf(subStr) in [0..Length(str)-Length(subStr)-1]);
end;
3条答案
按热度按时间2nc8po8w1#
使用
Pos
检查是否可以找到子字符串。然后检查子字符串是否位于末尾。字符串
chhkpiq42#
更多建议,重点放在一行程序上:
字符串
uurv41yg3#
这一个班轮应该给予你你想要的:
字符串
大卫的解决方案更干净,但我只想做一个班轮。