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
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › indexOf
String.prototype.indexOf() - JavaScript | MDN
The method returns the index of the first occurrence of the specified substring at a position greater than or equal to position, which defaults to 0. If position is greater than the length of the calling string, the method doesn't search the calling string at all.
🌐
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 the specified string in the current String object. Parameters specify the starting search position in the current string and the type of search to use for the specified string. public: ...
Discussions

String.indexOf function in C - Stack Overflow
Is there a C library function that will return the index of a character in a string? So far, all I've found are functions like strstr that will return the found char *, not it's location in the or... More on stackoverflow.com
🌐 stackoverflow.com
c# - What does string.IndexOf do? - Stack Overflow
I'm working through string manipulation, where I need to find characters or copy some part of the string that the user has input and divide it to 3 different areas. I'm not asking anything here about More on stackoverflow.com
🌐 stackoverflow.com
How does the `indexOf` method on a string work in JavaScript? - Stack Overflow
The first instance of the searched string "p" is at index 18. Therefore, when running this line: ... The result will be 18, the index of the first instance of the last character. (Side note: assuming you are a beginner when it comes to JavaScript - try not to use the var keyword whenever possible. If the variable needs to change, use let, or if the variable stays the same, use const.) ... Sign up to request clarification or add additional context in comments. ... Because indexOf ... More on stackoverflow.com
🌐 stackoverflow.com
Why can Indexof find string but not substring?
From u/SeeminglyScience on Discord, it's due to a change in culture and Unicode handling when .Net Core went cross-platform, .Net switched to use International Components for Unicode library. You need: .IndexOf("`n", [System.StringComparison]::Ordinal) to do a search ignoring culture-specific settings. Also it falls back to the "old way" if that library is not installed, so it works as you expect on (Win 10 + Windows PowerShell), or (Server 2019 + PowerShell 7 due to fallback as servers don't have icu yet), but it works differently on (Linux + PowerShell 7) and (Win 10 + PowerShell 7 which has the icu library). ( u/bis ) More on reddit.com
🌐 r/PowerShell
16
9
July 6, 2021
🌐
W3Schools
w3schools.com › java › ref_string_indexof.asp
Java String indexOf() Method
String myStr = "Hello planet earth, you are a great planet."; System.out.println(myStr.indexOf("planet")); Try it Yourself » · The indexOf() method returns the position of the first occurrence of specified character(s) in a string.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › String.html
String (Java Platform SE 8 )
October 20, 2025 - Returns: the index of the last ... character does not occur before that point. public int indexOf(String str) Returns the index within this string of the first occurrence of the specified substring....
🌐
Arduino
arduino.cc › en › Tutorial › StringIndexOf
String indexOf() and lastIndexOf() Method
String indexOf() and lastIndexOf() Method · How to Use String length() String length() and trim() Commands · String replace Function · String startsWith and endsWith Functions · String substring Function · String to Int Function · Button Mouse Control ·
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-string-indexof
Java String indexOf() Method - GeeksforGeeks
November 19, 2024 - In Java, the String indexOf() method returns the position of the first occurrence of the specified character or string in a specified string.
🌐
W3Schools
w3schools.com › jsref › jsref_indexof.asp
W3Schools.com
The indexOf() method returns the position of the first occurrence of a value in a string.
🌐
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 ·
🌐
Kotlin
kotlinlang.org › api › core › kotlin-stdlib › kotlin.text › index-of.html
indexOf | Core API – Kotlin Programming Language
fun CharSequence.indexOf(string: String, startIndex: Int = 0, ignoreCase: Boolean = false): Int(source) Returns the index within this char sequence of the first occurrence of the specified string, starting from the specified startIndex.
🌐
Medium
medium.com › @anandgupta20588 › indexof-vs-includes-method-to-search-a-string-character-f48cdf1261ee
indexOf() vs includes() method to search a string/character | by Anandgupta | Medium
November 2, 2023 - The indexOf() method is used to find the first occurrence of a specified string within another string. If the substring is found, it returns the index (position) of the first occurrence of the specified value.
🌐
Mimo
mimo.org › glossary › javascript › string-indexof-method
JavaScript String indexOf() method: Syntax, Usage, and Examples
The indexOf() method in JavaScript allows you to find the position of a substring within a string. It returns the index of the first occurrence or -1 if the substring doesn’t exist.
🌐
CodingBat
codingbat.com › doc › java-string-indexof-parsing.html
Java String indexOf Parsing
int indexOf(String target, int fromIndex) -- searches left-to-right for the target as usual, but starts the search at the given fromIndex. The fromIndex does not actually need to be valid. If it is negative, the search happens from the start of the string.
🌐
Dot Net Perls
dotnetperls.com › indexof-vbnet
VB.NET - String IndexOf Function - Dot Net Perls
November 15, 2023 - Module Module1 Sub Main() ' The string you are searching. Dim s As String = "Visual Basic rocks" ' Find index of uppercase letter B. Dim i As Integer = s.IndexOf("B"c) ' This new string contains the substring starting at B.
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › lang › String.html
String (Java Platform SE 7 )
Returns: the index of the last ... character does not occur before that point. public int indexOf(String str) Returns the index within this string of the first occurrence of the specified substring....
🌐
YouTube
youtube.com › anna mcdougall
What is the .indexOf() String Method? | JavaScript in LESS-THAN 3 | JavaScript Beginner Series - YouTube
Follow Me on Twitter: http://www.twitter.com/AnnaJMcDougallView String methods and properties on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript...
Published   December 18, 2020
Views   3K