C
C#13mo ago
Diesel Geezer

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

Or does it skip the specified index for the next?
12 Replies
Shinigami
Shinigami13mo ago
It searches for the specific char and give it's index
Diesel Geezer
Diesel Geezer13mo ago
yeah i know that. Thats not what im asking. Im asking at what index does the search begins
Shinigami
Shinigami13mo ago
0
Thinker
Thinker13mo ago
IndexOf begins at 0 by default, but there is an overload which lets you specify which index to begin from
MODiX
MODiX13mo 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
MODiX13mo 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
Thinker13mo ago
2 here specifies that the search should begin from index 2
Shinigami
Shinigami13mo ago
Ye you can provide the end index as well i.e till where tou want to search
Thinker
Thinker13mo ago
(it's a count but yes)
MODiX
MODiX13mo 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 Geezer13mo 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
Accord13mo 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.