I need INSTRREV to return the Int position of target within source after reverse (ie. backward) searching from start_pos to position of target.
I can't figure out how to get the position of target from target_char_range.
func INSTRREV( _ start_pos: Int,
_ source: String,
_ target: String ) -> Int
{
let start_index = source.index( source.startIndex, offsetBy: 0 )
let end_index = source.index( source.startIndex, offsetBy: start_pos - 1 )
let source_range = start_index..<end_index
let target_char_range = source.range( of: target,
options: .backwards,
range: source_range )
>>>>>>>> HOW TO CONVERT target_char_range INTO Int ? <<<<<<<<<<<
let target_pos: Int = 0
if target_pos > 0
{
return( target_pos )
}
else
{
return( 0 ) // not found
}
}