Case 语句中使用字符串 (转贴)

  • A+
所属分类:[开发技巧]

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:= '3000';
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.我有点看不懂后面部分

  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的微信公众号
  • 我的微信公众号扫一扫
  • weinxin
广告也精彩
avatar
广告也精彩

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: