Objective-C 中的子字符串

发布于 2024-12-19 09:01:29 字数 325 浏览 2 评论 0原文

我正在将一个示例从 C 转换为 Objective-C,并且有一个问题。

C/C++ 指令:

buffer[i].str = population[i1].str.substr(0, spos) + population[i2].str.substr(spos, esize - spos);

如何

使用 .substr(0, spos) Buffer 和 Population 来翻译 .substr(0, spos) 部分的向量。 str 是一个字符串变量 i、i1、i2、spos 和 esize 是整型变量。

I'm translating an example from C to Objective-C and have a questions.

C/C++ instruction:

buffer[i].str = population[i1].str.substr(0, spos) + population[i2].str.substr(spos, esize - spos);

How can I translate the part .substr(0, spos)

Buffer and population are vector using .
str is a string variable
i, i1, i2, spos and esize are integer variables.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

朮生 2024-12-26 09:01:29

使用 NSString 方法。

您有很多创建子字符串的方法。
主要是:

  • substringFromIndex:
  • substringWithRange:
  • substringToIndex:

.substr(0, spos) 可以翻译为:

[ someString substringToIndex: spos ];

注意,您首先需要将 C++ 字符串对象转换为 NSString 对象。

Use the NSString methods.

You've got a lot of methods for creating substrings.
Mainly:

  • substringFromIndex:
  • substringWithRange:
  • substringToIndex:

.substr(0, spos) may be translated to:

[ someString substringToIndex: spos ];

Note you will first need to convert your C++ string object to a NSString object.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文