打开字符串 [英] switch on strings
问题描述
如何实现stringse的开关盒...开关应该发生
取决于琴弦...
谢谢
sinbad
how to implement a switch case for stringse...switch should happen
depending on the strings...
thanks
sinbad
推荐答案
9月24日晚上11点19分,sinbad< sinbad.sin ... @ gmail。编写:
On Sep 24, 11:19 pm, sinbad <sinbad.sin...@gmail.comwrote:
如何为stringse实现切换案例...切换应该发生
取决于字符串...
how to implement a switch case for stringse...switch should happen
depending on the strings...
建议:在网上搜索完美哈希。
Suggestion: do a web search for "perfect hash".
>来自C FAQ:
>From the C FAQ:
20.17:有没有办法打开字符串?
答:不是直接的。有时,使用单独的
函数将字符串映射到整数代码是合适的,然后打开
那些。否则,当然,你可以使用传统的if / else链来减少strcmp()
和
。另见问题10.12,
20.18,
和20.29。
参考文献:K& R1 Sec。 3.4 p。 55; K& R2 Sec。 3.4 p。 58; ISO
秒6.6.4.2; H& S Sec。 8.7 p。 248.
20.17: Is there a way to switch on strings?
A: Not directly. Sometimes, it''s appropriate to use a separate
function to map strings to integer codes, and then switch on
those. Otherwise, of course, you can fall back on strcmp()
and
a conventional if/else chain. See also questions 10.12,
20.18,
and 20.29.
References: K&R1 Sec. 3.4 p. 55; K&R2 Sec. 3.4 p. 58; ISO
Sec. 6.6.4.2; H&S Sec. 8.7 p. 248.
sinbad写道:
sinbad wrote:
如何为stringse实现切换案例.. .switch应该发生
取决于字符串...
how to implement a switch case for stringse...switch should happen
depending on the strings...
交换机startement中的控制表达式必须是一个整数
类型。字符串不是整数类型。
你需要做的是将字符串映射到整数并使用
整数作为控制表达式切换声明。
The control expression in a switch startement must be of an integral
type. Strings are not of integral type.
What you need to do is to map the string onto an integer and use that
integer as the control expression in the switch statement.
9月25日上午11:49,Martin Ambuhl< mamb ... @ earthlink.netwrote:
On Sep 25, 11:49 am, Martin Ambuhl <mamb...@earthlink.netwrote:
sinbad写道:
sinbad wrote:
如何为stringse实现切换案例...切换应该发生
取决于字符串...
how to implement a switch case for stringse...switch should happen
depending on the strings...
switch switchement中的控制表达式必须是一个完整的
类型。字符串不是整数类型。
你需要做的是将字符串映射到整数并使用
整数作为控制表达式切换声明。
The control expression in a switch startement must be of an integral
type. Strings are not of integral type.
What you need to do is to map the string onto an integer and use that
integer as the control expression in the switch statement.
制图将有助于你。
Karthik Balaguru
Mapping will help u.
Karthik Balaguru
>
这篇关于打开字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!