检查String中是否存在\ n(Checking if \n exists in String - C)
我正在尝试比较两个字符串,即使它们看起来相同,但我没有得到匹配。 变成一个包含\ n的字符串。
所以我的问题是,是一种检查字符串是否包含'\ n'的方法吗? 我正在使用strcmp函数;
char *tempData; char *checkThis; tempData = "Hello \n"; checkThis = "Hello"; if(strcmp(tempData, checkThis) == 0) { printf("Match"); }I'm trying to compare two strings, and even though they look the same, I wasn't getting a match. Turns out one string contains \n.
So my question is, is a way to check if a string contains '\n'? I'm using the strcmp function;
char *tempData; char *checkThis; tempData = "Hello \n"; checkThis = "Hello"; if(strcmp(tempData, checkThis) == 0) { printf("Match"); }最满意答案
您可以在比较之前剥离空白区域,然后您不需要检查'\ n'。 但是你可以只比较字符串,假设这是你想要做的。
这个问题在C中如何做到这一点有一些答案。
You could strip the white-space before comparing, then you do not require a check for '\n'. But instead you can just compare the strings, assuming that is what you want to do.
This question has some answers on how to do that in C.
更多推荐
发布评论