gpt4 book ai didi

c# - 在 C# 中比较字符串和字符

转载 作者:行者123 更新时间:2023-11-30 14:37:57 24 4
gpt4 key购买 nike

假设有这样一个字符串

string temp2 = "hello";
char[] m = { 'u','i','o' };

Boolean B = temp2.Compare(m);

我想检查字符串是否包含我的字符数组?我正在尝试,但没有成功。关于编译消息

temp2.Compare(m) should be String type

来了。意味着它遵循 string.compare(string);我希望这不是应该有某种方法可以做到这一点的方式。

编辑//

我已经更正了 String.Compare 返回 bool 值这一行

最佳答案

如果您想确定字符串是否包含数组中的任何 个字符,您可以使用string.IndexOfAny功能。

bool containsAny = temp2.IndexOfAny(m) >= 0;

关于c# - 在 C# 中比较字符串和字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8632886/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com