现在的位置: 首页delphi精华>正文
Case 语句中使用字符串 (转贴)
2008年03月26日 delphi精华 暂无评论

function CaseString(const s: string; const x: array of string): Integer;
var
i: Integer;
begin
Result:= -1; //Default return parameter
for i:= Low(x) to High(x) do
begin
if s = x[i] then
begin
Result:= i;
Exit;
end;
end;
end;

search:= 'delphi3000';
case CaseString (search, ['delphi3000','delphipages','Torry's']) of
0: s:= 'Excellent!';
1: s:= 'Good source';
2: s:= 'Not bad!';
end;
/////////////////////////////////

const MatchingStrings = '*First*Second*Third*';
var sString: string;
...

// sString has the data you want to test
case pos('*'+sString+'*',MatchingStrings) of
1: // This is the match for 'First'
7: // This is the match for 'Second'
14: // This is the match for 'Third'
else // In this case there were no matches
end;

//===============================
PS.我有点看不懂后面部分

给我留言

留言无头像?


×
腾讯微博