I am a newbie in Swift. I use Swift 5.1 I want to get a substring from a string but I was not able to. I already tried several solutions(here, here) but those didn't work for me.
I tried it like this :
func substring(x : Int, y : Int, s : String) -> String {
let start = s.index(s.startIndex, offsetBy: x);
let end = s.index(s.startIndex, offsetBy: y);
return s[start..<end];
}
print(substring(x: 0, y: 2, s: "abcde"))
/tmp/306AE87E-57C7-417C-B2EF-313A921E75B9.BuUdsc/main.swift:6:11: error: subscript 'subscript(_:)' requires the types 'String.Index' and 'Int' be equivalent return s[start..(bounds: R) -> String where R : RangeExpression, R.Bound == Int { get } ^
I really appreciate your help. Thank you.