python - 如何在 objective-c 中使用 Python 中的 str.translate() 方法?

标签 python ios translate

所以标题解释了大部分内容。我开始为 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!!!

最佳答案

就我而言,没有像 translate() 这样的内置方法。 (但是,您可以使用 PyObjc 在 Objective C 中获得完全相同的功能,请查找)

你可以尝试用 replaceOccurrencesOfString:withString:options:range 做点什么在 NSMutableString 上或自己编写一个函数,使用一个循环查看字符串中的每个字符,检查是否必须替换它,如果是,则用正确的字符替换它。 (因为这就是 translate() 函数的作用,对吧?)

关于python - 如何在 objective-c 中使用 Python 中的 str.translate() 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12763253/

相关文章:

python - PyCharm 无法解析对 PyQT5 模块的引用

ios - 指针传递 Objective C 或 C 语法

python - 在 Python 中使用 Yandex 翻译 API 时出现问题

python : comma in print as "\t"

python - login_required 装饰器不起作用,flask-Login 允许匿名用户

Python 3.3 - 需要帮助使用 .txt 中的数据编写 .png 文件

ios - 找到纸角

iPhone - 确定 ImageView 显示的图像

ios - 如何根据设备语言使用不同的数组?

java - 将位修改代码从 C 移植到 Java