indexOf Method

Ronald Rex 1,666 Reputation points
2023-07-31T19:26:38.67+00:00

Hello Friends I was wondering if I have a string of values held in a variable of type string called strValues . e.g. string strValues ="COY,RAY,REX"; The passed in variable that references the value is RAY can I use this variable to find out if one of the values is in the 0th index of a value like so if(strValues.indexOf(value)==0). Do I need to use an array? I just want to keep my code as Terse as possible. Thanks for any help.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,285 questions
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 71,186 Reputation points
    2023-08-01T16:23:50.1666667+00:00

    or just:

    	var strValues = "COY,RAY,REX".Split(','); 
    	if(Array.IndexOf(strValues, value) == 0)
    
    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.