美文网首页
iOS - 字符反转

iOS - 字符反转

作者: lizhi_boy | 来源:发表于2020-04-09 15:26 被阅读0次

    swift代码:思路是:反向读取+字符拼接

        func charAtReverse(_ str:String) -> String {
            var reverseStr:String = "";
            for i in 0..<str.count {
                let j = str.count-i-1;
                let currentIndex = str.index(str.startIndex, offsetBy:j);
                let currentStr = str[currentIndex]
                reverseStr.append(currentStr);
            }
            return reverseStr;
        }
    

    相关文章

      网友评论

          本文标题:iOS - 字符反转

          本文链接:https://www.haomeiwen.com/subject/pcucmhtx.html