swift - 如何快速将单词分解为字符

标签 swift func

我怎样才能在 swift 2 中做同样的事情:

String a = "danial";
  for (int i= 0 ; i < a.length() ; i++) {
    System.out.println(a.charAt(i));
  }
}

最佳答案

试试这个:

let myString = "danial"
let characters = Array(myString.characters)
print(characters) //OP : ["d","a","n","i","a","l"]
print(characters[0]) //OP : ["d"]

关于swift - 如何快速将单词分解为字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32664401/

相关文章:

ios - 将数据从 TableViewCell 标签传递到 ViewController 时出现问题

Swift 可选转义闭包

c# - 如何找出委托(delegate)返回 void ?

c# - 为什么成员字段不能有字段初始值设定项调用成员函数?

c# - 在 Action 方法中调用的好方法

ios - 如何使用google api获取用户位置

ios - 两次之间的分钟数

ios - 获取文本字段上的 "bottom space to superview"约束

c# - Func<> 委托(delegate) - 说明

swift - 将选择器(函数名称)传递给 swift 函数