BenGoldberg
0
Q:

find first occurrence of character in string

  // Initialising String 
        String gfg = new String("Welcome to geeksforgeeks"); 
  
        System.out.print("Found g first at position : "); 
  
        // Initial index of 'g' will print 
        // prints 11 
        System.out.println(gfg.indexOf('g')); 
3
// applies to C#
string S = "Any String At All"
int Sindex = S.indexOf("A") // accepts string or char arguments. 

// "Sindex" would be equal to "0", as the indexOf(); meathod returns
// the index position of the first occurance of the specified argument.
0

New to Communities?

Join the community