【问题标题】:How do i add to a mutable string in objective c?如何添加到目标 c 中的可变字符串?
【发布时间】:2012-10-04 18:59:34
【问题描述】:

在没有深入了解实际程序的情况下,我想获取一个现有的字符串并向其添加更多字符(或字符串)。如果这是在java中完成的,它会是这样的

字符串 x= "你好"

x= x + "世界";

我目前有我的字符串试图这样做。我声明的字符串称为 _whatiscorrect,它现在是一个空字符串,在此示例中,我想获取现有字符串并为其添加一个“o”。

_whatiscorrect = [_whatiscorrect stringByAppendingString:@"o"]; // 在字符串中放置一个o

我该怎么做?

【问题讨论】:

    标签: string character add mutable


    【解决方案1】:

    你的想法是对的。只需这样做:

    NSMutableString * _whatiscorrect = [[NSMutableString alloc] initWithString: @".."];
    [_whatiscorrect appendString:@"o"];
    

    【讨论】:

      猜你喜欢
      • 2013-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-06
      • 2015-03-09
      • 2021-12-30
      • 2023-03-12
      • 2015-11-14
      相关资源
      最近更新 更多