P pdjwind Unregistered / Unconfirmed GUEST, unregistred user! 2003-04-09 #1 case语句只支持顺序类型,怎么把字符改成顺序的呢? (字符串也是无序的,如:BY,ZC,CX...)
P pdjwind Unregistered / Unconfirmed GUEST, unregistred user! 2003-04-09 #3 case 字符串 of 字符串1 : 过程1; 字符串2 : 过程2; 字符串3 : 过程3; else 过程4; end;
R ReallyFail Unregistered / Unconfirmed GUEST, unregistred user! 2003-04-09 #4 字符串不行的,如果是单个字符的话到是可以用ORD函数来写
J jrq Unregistered / Unconfirmed GUEST, unregistred user! 2003-04-09 #5 看看这个吧,很多解决方案的: http://www.delphibbs.com/delphibbs/dispq.asp?lid=1358621
B beta Unregistered / Unconfirmed GUEST, unregistred user! 2003-04-09 #6 我就知道会有人问这个问题[] http://www.delphibbs.com/delphibbs/dispq.asp?lid=1358621
C cwmdelpher Unregistered / Unconfirmed GUEST, unregistred user! 2003-04-09 #7 case结构不支持了符串检索,怎么办 do like this: const strArray : array [0..10] of string =(['str0', 'str1', 'str2', ...); for i := 0 to 10 do if strArray = str then case i of 0: do str1 thing 1: do str1 thing 2: ... end; ***************** function CaseString (const s: string // Search for ci: Boolean; // if true looking case insensitive p: Boolean; // if true looking if s is in the compared string const x: array of string): Integer; var i: Integer; s1, s2: string; begin Result:= -1; for i:= Low (x) to High (x) do begin s1:= s s2:= x; if ci then begin AnsiUpperCase(s1); AnsiUpperCase(s2); end; if p then begin if Pos (s1, s2) > 0 then begin Result:= i Exit end; end else begin if s1 = s2 then begin Result:= i Exit end; 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; *************************************************** uses TypInfo; type TNumericChoiceParent = (ncp_Mother, ncp_Father, ncp_Child); procedure TForm1.btChooseClick(Sender: TObject); var S: string; begin S := InputEdit.Text; case TNumericChoiceParent(GetEnumValue(TypeInfo(TNumericChoiceParent), 'ncp_' + S)) of ncp_Mother: ShowMessage('Hello Mom )'); ncp_Father: ShowMessage('Hi, Dad -]'); ncp_Child: ShowMessage('Shut up and eat your soup !-('); else ShowMessage('Who do you think that you are?'); end; end;
case结构不支持了符串检索,怎么办 do like this: const strArray : array [0..10] of string =(['str0', 'str1', 'str2', ...); for i := 0 to 10 do if strArray = str then case i of 0: do str1 thing 1: do str1 thing 2: ... end; ***************** function CaseString (const s: string // Search for ci: Boolean; // if true looking case insensitive p: Boolean; // if true looking if s is in the compared string const x: array of string): Integer; var i: Integer; s1, s2: string; begin Result:= -1; for i:= Low (x) to High (x) do begin s1:= s s2:= x; if ci then begin AnsiUpperCase(s1); AnsiUpperCase(s2); end; if p then begin if Pos (s1, s2) > 0 then begin Result:= i Exit end; end else begin if s1 = s2 then begin Result:= i Exit end; 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; *************************************************** uses TypInfo; type TNumericChoiceParent = (ncp_Mother, ncp_Father, ncp_Child); procedure TForm1.btChooseClick(Sender: TObject); var S: string; begin S := InputEdit.Text; case TNumericChoiceParent(GetEnumValue(TypeInfo(TNumericChoiceParent), 'ncp_' + S)) of ncp_Mother: ShowMessage('Hello Mom )'); ncp_Father: ShowMessage('Hi, Dad -]'); ncp_Child: ShowMessage('Shut up and eat your soup !-('); else ShowMessage('Who do you think that you are?'); end; end;
F firstrose Unregistered / Unconfirmed GUEST, unregistred user! 2003-04-11 #8 case 字符串的hash(比如crc) 我是说,把字符串用唯一不重复的数表示