【发布时间】:2012-09-27 14:43:18
【问题描述】:
所以标题解释了大部分内容。我开始为 iOS 开发 Objective c,但我还没有发现是否有办法在 Objective c 中使用类似 translate() 的方法。
这是我在python中使用的程序。:
#!/usr/bin/python
from string import maketrans # Required to call maketrans function.
intab = "aeiou"
outtab = "12345"
trantab = maketrans(intab, outtab)
str = "this is string example....wow!!!";
print str.translate(trantab);
输出:
th3s 3s str3ng 2x1mpl2....w4w!!!
【问题讨论】:
-
str是 Python 中的内置名称;不要覆盖它。 -
他的例子直接来自这里:tutorialspoint.com/python/string_translate.htm。我还假设他知道它是基于标题内置的。