如何比较C中的两个字符串? [英] How do I compare two string in C?

查看:76
本文介绍了如何比较C中的两个字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想比较两个字符串并找出这两个字符串的相似程度。

strcmp我认为不是一个好主意。

例如我们有3个字符串。我需要找出字符串1和2的相似性更高或字符串1和3的相似性。任何想法?



我想要比较两个数据包的有效负载。< br $> b $ b

谢谢



我们在c中有这样的比较功能吗?



我尝试了什么:



string str1 =我是第一串

string str2 =我是第二个字符串

string str3 =这是字符串编号3

int similarity12,similarity13;

similarity12 = compare(str1,str2);

similarity13 = compare(str1,str3);

Hi, I want to compare two string and find out how much this two strings are similar.
strcmp is not a good idea I think.
for example we have 3 strings. I need to find out similarity of string 1 and 2 is higher or similarity of string 1 and 3. Any Idea?

I want this for comparing two packet's payload.

thanks

Do we have such compare function in c?

What I have tried:

string str1 = "I am string number one"
string str2 = "I am string number two"
string str3 = "this is string number 3"
int similarity12,similarity13;
similarity12 = compare(str1,str2);
similarity13 = compare(str1,str3);

推荐答案

听起来你可能会想 Levenshtein距离 - 维基百科 [ ^ ]
It sounds like you might want Levenshtein distance - Wikipedia[^]


这篇关于如何比较C中的两个字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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