如何在获取字符串时按下该转义键 [英] how to find that escape key is pressed while taking the string

查看:64
本文介绍了如何在获取字符串时按下该转义键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi


当接受字符串作为输入时,如何检查转义键是否被按下。

因为如果用户按下我不想收到字符串ESCAPE

键..我使用ascii代码进行比较,但我没有得到任何富有成果的

结果。请帮帮我。

hi

how to check escape key is pressed when accepting the string as input.
Because I do not want to receive a string if user presses the ESCAPE
key.. I used ascii code for comparision but I didn''t get any fruitful
results. Please help me.

推荐答案

文章< 11 **************** ******@g43g2000cwa.googlegroups .com> ;,

sudhir< su ***************** @ gmail.com>写道:
In article <11**********************@g43g2000cwa.googlegroups .com>,
sudhir <su*****************@gmail.com> wrote:
当接受字符串作为输入时,如何检查转义键。
因为如果用户按下ESCAPE
键我不想收到字符串..我使用ascii代码进行比较,但我没有得到任何富有成果的结果。请帮帮我。
how to check escape key is pressed when accepting the string as input.
Because I do not want to receive a string if user presses the ESCAPE
key.. I used ascii code for comparision but I didn''t get any fruitful
results. Please help me.




转义键不可移动;-)


如果你有一个输入字符串,你知道是ASCII(或ISO-8859- *)

然后你可以根据ASCII转义值测试每个字符,你可以用几种不同的方式编码。其中一种方式是


#include< string.h>

#define ESCAPE''\ 027''

.....


if(strchr(STRING,ESCAPE)!= NULL){/ *你有一个ESCAPE * /}


请注意,您的操作系统或shell可能是正在进行操作。在发送给你之​​前逃脱

字符。防止发生b / b $ b的机制是特定于操作系统的,并且在特定于您的操作系统的

新闻组中进行了最佳探索。


-

没有人有权通过要求经验证据来摧毁另一个人的信念。 - Ann Landers



The escape key isn''t portable ;-)

If you have an input string that you know to be ASCII (or ISO-8859-*)
then you can test each character against the ASCII escape value, which
you can code in several different ways. One such way would be

#include <string.h>
#define ESCAPE ''\027''

.....

if ( strchr( STRING, ESCAPE ) != NULL ) { /* you got an ESCAPE */ }

Note that your operating system or shell might be "eating" the escape
character before sending it on to you. Mechanisms to prevent that
happening are operating-system specific and best explored in a
newsgroup specific to your operating system.

--
"No one has the right to destroy another person''s belief by
demanding empirical evidence." -- Ann Landers


" sudhir" <苏***************** @ gmail.com>写道:
"sudhir" <su*****************@gmail.com> writes:
当接受字符串作为输入时,如何检查转义键。
因为如果用户按下ESCAPE
键我不想收到字符串..我使用ascii代码进行比较,但我没有得到任何富有成果的结果。请帮帮我。
how to check escape key is pressed when accepting the string as input.
Because I do not want to receive a string if user presses the ESCAPE
key.. I used ascii code for comparision but I didn''t get any fruitful
results. Please help me.




请帮助我们帮助您。如果你要告诉我们你试过的代码

*和*告诉我们它是如何行为不端的,我们可以帮你确定它为什么

没有工作。


如果你想在

用户按ESCAPE时立即终止尝试读取一行,那么就没有可移植的方式来做;请参阅comp.lang.c FAQ中的问题

19.1< http://www.eskimo.com/~scs/C-faq/faq.html>。


Walter Roberson也给了你一些很好的建议。


-

Keith Thompson(The_Other_Keith) ks *** @ mib.org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *> < http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。



Please help us to help you. If you''ll show us the code you''ve tried
*and* tell us how it misbehaves, we can help you determine why it
doesn''t work.

If you want to terminate the attempt to read a line immediately if the
user presses ESCAPE, there''s no portable way to do that; see question
19.1 in the comp.lang.c FAQ, <http://www.eskimo.com/~scs/C-faq/faq.html>.

Walter Roberson''s also gave you some excellent advice.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


sudhir写道:
当接受字符串作为输入时,如何检查转义键。
因为如果用户按下ESCAPE
键我不想收到字符串..我使用ascii代码进行比较,但我没有得到任何富有成果的结果。请帮助我。
how to check escape key is pressed when accepting the string as input.
Because I do not want to receive a string if user presses the ESCAPE
key.. I used ascii code for comparision but I didn''t get any fruitful
results. Please help me.




你将不得不使用一些系统特定的扩展,所以我建议你在一个致力于任何一个系统的小组中询问
你正在使用。

-

Flash Gordon

生活在有趣的时代。

虽然我的电子邮件地址说垃圾邮件,它是真实的,我读了它。



You will have to use some system specific extension, so I suggest you
ask in a group dedicated to whichever system you are using.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.


这篇关于如何在获取字符串时按下该转义键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆