当我使用 createFileAtPath
时,我有大约 20 行文本需要替换其中的一些值
例如
[firstname] has a surname of [surname]
and is [gender]
etc etc etc
etc etc etc
etc etc etc
etc etc etc
and lives in [suburb]
当用户单击按钮时,我必须多次创建此文件
这可以通过创建某种模板或常量来完成,我可以用我的变量替换占位符吗?与 NSString stringWithFormat
类似的东西称为
[NSString stringWithFormat:myTemplate, person.firstname, person.surname, person.gender, person.suburb]
最佳答案
我会看看 NSRegularExpression -replaceMatchesInString:options:range:withTemplate:。您可以匹配 NSMutableString 中的某些内容并替换它。
关于objective-c - 创建文件模板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9533586/