-1

I have a list arrString that contains string values. I need to check a string lookupvalue.Longname whether it exists in the list using for loop in C#.

 for(int i = 0 ;i < ResoCustomFields.LongnameNotToBeTaken.Count ;i++)
 {
    string myStringList = ResoCustomFields.LongnameNotToBeTaken[i].ToString();
    var arrString = myStringList.Trim('(',')').Split(',').ToList();
    if(arrString.Contains(resoField))
    {
    // if(!arrString[i].Any(str=>str.ToString().Contains(lookupValue.LongName)))
    // if(lookupValue.LongName.Contains(arrString.ToString()))
    //(!arrString.Any(str => str.Equals(lookupValue.LongName)))
    // if(!arrString.Equals(lookupValue.LongName))                                                      
    {
    }
}
9
  • 1
    Possible duplicate of Check if list contains element that contains a string and get that element Commented Apr 11, 2017 at 6:57
  • if (ResoCustomFields.LongnameNotToBeTaken.Any(line => line.Trim('(',')').Split(',').Any(item => item == resoField))) {...} Commented Apr 11, 2017 at 6:59
  • i tried arrString[i].Contains(lookupValue.LongName)..still its not working Commented Apr 11, 2017 at 7:01
  • i have already done trim and split.. Commented Apr 11, 2017 at 7:05
  • Can you give a small example of arrString and resoField? Commented Apr 11, 2017 at 7:05

1 Answer 1

0

You can try the following code :

int pos = Array.IndexOf(arrString, lookupValue.LongName);
if (pos > -1)
{
//// DO YOUR STUF
}

Following is the reference:

Checking if a string array contains a value, and if so, getting its position

Sign up to request clarification or add additional context in comments.

1 Comment

i tried ,but the index is always -1 even if the string values contain in list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.