问题描述
我想使用
string.h头文件中的strrchar(source_string,last_char)函数来查找最后一次出现的非空格
字母数字字符。
然后我会在递增该位置后放置一个NULL CHAR,并通过strrchar()函数收到
。
这是我从右边修剪一个字符串的想法。
根据strrchar函数的定义,我应该为
提供字符串并且该字符必须在最后一次出现时检查
。但我想设置一种方法来检查GENRIC ALPHANUMERIC CHARACTER的最后一次出现
,而不是任何
特定字符。
我们在C中有任何GENERIC预定义宏,用于
INTEGERS,CHARACTERS .. .etc。
是否有更好更快的解决方案正确修剪大字符串
?
谢谢提前。
Reg ards,
shamdurgs
使用我的...
char * rtrim(char * str){
char * s,* p; int c;
s = p = str;
while((c = * s ++))if(!isspace(c))p = s;
* p =''\ 0'';
返回str;
}
-
Joe Wright mailto:jo ******** @ comcast.net
所有内容都应尽可能简单,但并不简单。
--- Albert Einstein ---
实际上,就像< ctype.h>中原型的所有函数一样,isalnum
需要一个int ,而不是char。
标准说:
4.3.1.1 isalnum功能
概要
#include< ctype.h>
int isalnum(int c);
描述
isalnum函数测试任何字符为isalpha或
isdigit为真。
I want to use strrchar(source_string,last_char ) function from
string.h header file,to find out the last occurrence of the NON SPACE
Alphanumeric Character.
Then i will put a NULL CHAR after incrementing that position,received
by strrchar() function by 1.
This is my idea of Trimming a string from right .
According to the definition of the strrchar function,i am supposed to
provide the string and that character that has to be checked for the
last occurrence.But i want to device a way to check the last
occurrence of a "GENRIC ALPHANUMERIC CHARACTER",rather than any
specific character.
Have we got any GENERIC Predefined Macro in C ,for
INTEGERS,CHARACTERS...etc.
Is there any better and fast solution for Right Trimming a Big string
?
Thanks in Advance.
Regards,
shamdurgs
Use mine ..
char * rtrim(char *str) {
char *s, *p; int c;
s = p = str;
while ((c = *s++)) if (!isspace(c)) p = s;
*p = ''\0'';
return str;
}
--
Joe Wright mailto:jo********@comcast.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Actually, like all the functions prototyped in <ctype.h>, isalnum
takes an int, not a char.
The Standard says:
4.3.1.1 The isalnum function
Synopsis
#include <ctype.h>
int isalnum(int c);
Description
The isalnum function tests for any character for which isalpha or
isdigit is true.
这篇关于对于INTEGERS,CHARACTERS,c中是否有任何GENRIC MACROS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!