检查String中是否存在\ n(Checking if \n exists in String

编程入门 行业动态 更新时间:2024-10-23 22:28:35
检查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.

更多推荐

本文发布于:2023-08-07 18:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465066.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:是否存在   String   exists   Checking

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!