问个问题:判断字符串采取相应的处理,我想用case语句,不想用if,怎么办?(20分)

P

pdjwind

Unregistered / Unconfirmed
GUEST, unregistred user!
case语句只支持顺序类型,怎么把字符改成顺序的呢?
(字符串也是无序的,如:BY,ZC,CX...)
 
什么意思?理解不了??
 
case 字符串 of
字符串1 : 过程1;
字符串2 : 过程2;
字符串3 : 过程3;
else
过程4;
end;
 
字符串不行的,如果是单个字符的话到是可以用ORD函数来写
 
看看这个吧,很多解决方案的:

http://www.delphibbs.com/delphibbs/dispq.asp?lid=1358621
 
我就知道会有人问这个问题[:D]

http://www.delphibbs.com/delphibbs/dispq.asp?lid=1358621

 
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 :eek:)');

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 字符串的hash(比如crc)
我是说,把字符串用唯一不重复的数表示
 
建立一个集合!
 

Similar threads

S
回复
0
查看
964
SUNSTONE的Delphi笔记
S
S
回复
0
查看
785
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
781
import
I
顶部