strstr returns a pointer to the found character, so you could use pointer arithmetic: (Note: this code not tested for its ability to compile, it's one step away from pseudocode.)

Copychar * source = "test string";         /* assume source address is */
                                       /* 0x10 for example */
char * found = strstr( source, "in" ); /* should return 0x18 */
if (found != NULL)                     /* strstr returns NULL if item not found */
{
  int index = found - source;          /* index is 8 */
                                       /* source[8] gets you "i" */
}
Answer from Bill on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c# โ€บ c-sharp-string-indexof-method-set-1
C# String.IndexOf( ) Method | Set - 1 - GeeksforGeeks
July 11, 2025 - In C#, the IndexOf() method is a String method. Used to find the zero-based index of the first occurrence of a specified character or string within the current instance of the string. The method returns -1 if the character or string is not found.
๐ŸŒ
Arduino Forum
forum.arduino.cc โ€บ projects โ€บ programming
indexOf equivalent for c-string ? - Programming - Arduino Forum
April 11, 2020 - As i am working on a project that needs to check responses of the SIM800l to AT-commands, i easily want to be able to check for keywords within a c-string. I am using a Mega, which does have quite a lot of memory but it'โ€ฆ
๐ŸŒ
Processing
processing.org โ€บ reference โ€บ string_indexof_
indexOf() / Reference - String
String str = "CCCP"; int p1 = str.indexOf("C"); int p2 = str.indexOf("P"); int p3 = str.indexOf("CP"); println(p1 + ":" + p2 + ":" + p3); // Prints "0:3:2" str.indexOf(str) str.indexOf(str, fromIndex) strString: any variable of type String ยท strString: the substring to search ยท
๐ŸŒ
Arduino
docs.arduino.cc โ€บ built-in-examples โ€บ strings โ€บ StringIndexOf
String indexOf() and lastIndexOf() Method
Learn the basics of Arduino through this collection tutorials. All code examples are available directly in all IDEs
๐ŸŒ
Aspose
reference.aspose.com โ€บ api reference โ€บ page โ€บ c++ โ€บ system โ€บ string โ€บ indexof
System::String::IndexOf method | Aspose.Page for C++
November 26, 2025 - Index of first character position since startIndex or -1 if not found. ... Substring forward lookup. int System::String::IndexOf(const String &str, int startIndex, int count) const
๐ŸŒ
Learneroo
learneroo.com โ€บ modules โ€บ 26 โ€บ nodes โ€บ 187
More String Methods - Learneroo
Below are 3 additional String methods. After reviewing them, you should be able to solve the challenges and tasks below and the challenges in String Programming Practice. indexOf indexOf(c) - Finds the character 'c' within the String and returns the index where 'c' first occurs.
Find elsewhere
๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ dotnet โ€บ api โ€บ system.string.indexof
String.IndexOf Method (System) | Microsoft Learn
Reports the zero-based index of the first occurrence of a specified Unicode character or string within this instance. The method returns -1 if the character or string is not found in this instance.
๐ŸŒ
Programiz
programiz.com โ€บ csharp-programming โ€บ library โ€บ string โ€บ indexof
C# String IndexOf() (With Examples)
The String IndexOf() method returns the index of the first occurrence of the specified character/substring within the string. In this tutorial, we will learn about the C# String IndexOf() method with the help of examples.
๐ŸŒ
Reddit
reddit.com โ€บ r/csharp โ€บ how to use indexof(string, int32, int32)
r/csharp on Reddit: How to use IndexOf(String, Int32, Int32)
December 6, 2023 -

I'm new to C#. What is wrong with these lines of code?

if (inventory.Contains(input.Substring(4, input.Length - 5)))
{
    invPosition = inventory.IndexOf(input.Substring(4, input.Length - 5), 0, input.Length - 5);
    inventory[invPosition] = "";
    Console.WriteLine(inventory[invPosition] + " has been dropped");
    invSize--;
}

I'm trying to create a basic code which allows you to summon an object into an array and remove it.

The command words for these are "GET" and "DROP".

At this position of the code, I want the user to type "DROP x". I want my code to check if 'x' has already been summoned. If it has, I want x to be dropped and removed from the array. To do this, I am trying to use the IndexOf Method, to try and find the position of 'x' in the array and remove it. However, my error for IndexOf says "cannot convert from string to System.Array". Can anybody help?

๐ŸŒ
Sololearn
sololearn.com โ€บ en โ€บ Discuss โ€บ 2182812 โ€บ how-to-find-index-of-string-in-c
How to find index of string in c++ | Sololearn: Learn to code for FREE!
Adding to above: size_t index= str.find(str1); It return index of first occurrence of str1 string from owl str string... Ex: str="ab cdef" ; str1="ab" ; size_t index= str.find(str1); index=0; //at 0 position...
๐ŸŒ
Quora
quora.com โ€บ in-C-what-is-the-simplest-way-to-get-the-index-of-the-first-character-of-a-string-within-a-phrase-knowing-only-the-address-of-that-string
In C, what is the simplest way to get the index of the first character of a string (within a phrase), knowing only the address of that string? - Quora
Answer (1 of 6): Question: in C, what is the simplest way to get the index of the first character of a string (within a phrase), knowing only the address of that string? Oh thatโ€™s easy. You should be familiar with the strlen() function.so - ...
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ what-is-stringindexof-in-c-sharp
What is String.IndexOf() in C#?
In C#, the String.IndexOf() is a string method used to find the location of a character or substring within the String object.
๐ŸŒ
W3Schools
w3schools.com โ€บ cpp โ€บ cpp_strings_access.asp
C++ Accessing Strings
You can access the characters in a string by referring to its index number inside square brackets [].
๐ŸŒ
Dot Net Perls
dotnetperls.com โ€บ indexof
C# - String IndexOf Examples - Dot Net Perls
It returns the index of the string part, if one is found. If the substring or char is not found, IndexOf returns -1.