❔ Does indexof search for the specified character at the specified index?

Or does it skip the specified index for the next?
12 Replies
Shinigami
Shinigami3y ago
It searches for the specific char and give it's index
Diesel Geezer
Diesel GeezerOP3y ago
yeah i know that. Thats not what im asking. Im asking at what index does the search begins
Shinigami
Shinigami3y ago
0
Thinker
Thinker3y ago
IndexOf begins at 0 by default, but there is an overload which lets you specify which index to begin from
MODiX
MODiX3y ago
thinker227
REPL Result: Success
"12313".IndexOf('1')
"12313".IndexOf('1')
Result: int
0
0
Compile: 510.736ms | Execution: 26.074ms | React with ❌ to remove this embed.
MODiX
MODiX3y ago
thinker227
REPL Result: Success
"12313".IndexOf('1', 2)
"12313".IndexOf('1', 2)
Result: int
3
3
Compile: 437.160ms | Execution: 24.093ms | React with ❌ to remove this embed.
Thinker
Thinker3y ago
2 here specifies that the search should begin from index 2
Shinigami
Shinigami3y ago
Ye you can provide the end index as well i.e till where tou want to search
Thinker
Thinker3y ago
(it's a count but yes)
MODiX
MODiX3y ago
thinker227
REPL Result: Success
"12313".IndexOf('1', 1, 2)
"12313".IndexOf('1', 1, 2)
Result: int
-1
-1
Compile: 460.137ms | Execution: 27.880ms | React with ❌ to remove this embed.
Diesel Geezer
Diesel GeezerOP3y ago
so if i put 2 as start index, it will also search the character at index 2 and not skip it and go to index 3
Accord
Accord3y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.

Did you find this page helpful?