This is a sample code that assumes ASCII code only and starts with 0 (0 origin) and starts with -1 odd characters only.
let str="abcdef"
vars=""
for(i,ch)instr.utf8.enumerated(){
ss.append(String(UnicodeScalar(i%2==1&ch>0?ch-1:ch)))
}
print(ss)//"aaccee"
© 2024 OneMinuteCode. All rights reserved.