搜索char * [英] Searching in char*

查看:65
本文介绍了搜索char *的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

检查33到47之间的任何ASCII字符的最佳方法是什么?$ *
存在于字母*?

解决方案

< blockquote> spl写道:


检查33到47之间的任何ASCII字符的最佳方法

存在于char *中?



为了获得最大的可移植性,请使用ispunct()函数。否则使用

类似于:


if(ch> = 33&& ch< = 47)/ * ... * /


这当然特定于ASCII编码。使用ispunct可能比b
更好,但除了那些在ASCII 33到47之内的那些

之外,这可能会返回true,在这种情况下你进行了进一步的检查。


另一种可能性是转换声明:


switch(ch){

case''!'':

case''"'':

case''#'':

/ *依此类推* /

默认:

/ *不匹配* /

}


santosh写道:


spl写道:


>检查33到47之间任何ASCII字符的最佳方法是什么
存在于char *中?



为了获得最大的可移植性,请使用ispunct()函数。否则使用

类似于:


if(ch> = 33&& ch< = 47)/ * ... * /



哎呀。没有抓到char * bit。使用类似的东西:


bool isASCIIpunct(const char * restrict str){

bool rc = false;

while(* str ++){

if(* str> = 33& * str< = 47){

rc = true;

休息;

}

}

返回rc;

}


< snip>


不,这只是好的,如果我搜索一个字符,但我的是256

字符串,因为我必须找到任何出现的Ascii

字符btw 34到47.


What is the best way to check any ASCII characters between 33 to 47
exists in a char*?

解决方案

spl wrote:

What is the best way to check any ASCII characters between 33 to 47
exists in a char*?

For maximal portability use the ispunct() function. Otherwise use
something like:

if (ch >= 33 && ch <= 47) /* ... */

This is of course specific to ASCII encoding. Using ispunct may be
better but that might return true for punctuation other than those
within ASCII 33 to 47, in which case you have perform further checks.

Another possibility is a switch statement:

switch (ch) {
case ''!'':
case ''"'':
case ''#'':
/* and so on */
default:
/* not matching */
}


santosh wrote:

spl wrote:

>What is the best way to check any ASCII characters between 33 to 47
exists in a char*?


For maximal portability use the ispunct() function. Otherwise use
something like:

if (ch >= 33 && ch <= 47) /* ... */

Oops. Didn''t catch the char * bit. Use something like:

bool isASCIIpunct(const char *restrict str) {
bool rc = false;
while (*str++) {
if (*str >= 33 && *str <= 47) {
rc = true;
break;
}
}
return rc;
}

<snip>


No, this is fine only, if I search a single character, but mine is 256
character string, in that I have to find any occurance of the Ascii
characters btw 34 to 47.


这篇关于搜索char *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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