如何检查所有数组元素中是否不存在字符串 [英] How to check if a string not exist in all array elements

查看:98
本文介绍了如何检查所有数组元素中是否不存在字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串数组,我想看看它的一个元素是否不包含在另一个字符串中,所以不要在我的代码中调用名为onefive的函数,而不是在字符串的input1数组中调用s1字符串。代码工作,但我的问题,我不想要如果(wo)是来自s1的子串,但就好像整个字符串例如假设:



input1 = {info,text ,汽车};

s1 =信息胡萝卜;



函数(onefive)将不会在第一个元素信息中调用第三元素汽车,因为信息是来自信息的子串,汽车是胡萝卜的子串,但我不想要那个!



我需要帮助,但不使用正则表达式,因为它剂量以我的语言工作!



我的尝试:



I have an array of string and I want to see if an element of it not contained in another string, so dont call the function named onefive in my code below input1 array of string while s1 string. the code works but my problem I dont want if (wo) is a substring from s1 but just if whole string for instance suppose that:

input1={info, text, car};
s1="information carrot";

the function (onefive) will not be called in first element info and the third element car because info is a substring from information and car is a substring from carrot but I dont want that!

please I need help but without using Regex because it dosent work in my language!

What I have tried:

foreach (string wo in input1)
            {
                if (!s1.Contains(wo))
                {
                    zo = zo+onefive(wo);
                    
                }
            }

推荐答案

那么你应该寻找字符串相等,检查一下out: String.Equals [ ^ ]
Then you should be looking for equality of strings, check this out: String.Equals[^]


这篇关于如何检查所有数组元素中是否不存在字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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