Objective c 我想在目标c中的字符串之间添加一个空格

Objective c 我想在目标c中的字符串之间添加一个空格,objective-c,ios7,nsstring,Objective C,Ios7,Nsstring,NSString*two=[blank.stringByAppendingString:one,索引(2)] 在方法调用中,在blank之后有一个无关的。删除它和索引(2),您的代码应该工作得更好 使用可变字符串可以改进代码。您可以使用-insertString:atIndex:并避免需要所有这些中间字符串 更新:您还应该更改新变量的名称新< /Cord>是NSObject中的方法的名称,也是C++中的保留字。使用它作为变量名应该可以,但将来肯定会导致混淆。您的noSpace值是多少?而且你的代

NSString*two=[blank.stringByAppendingString:one,索引(2)]

在方法调用中,在
blank
之后有一个无关的
。删除它和
索引(2)
,您的代码应该工作得更好

使用可变字符串可以改进代码。您可以使用
-insertString:atIndex:
并避免需要所有这些中间字符串


更新:您还应该更改
新变量的名称<代码>新< /Cord>是NSObject中的方法的名称,也是C++中的保留字。使用它作为变量名应该可以,但将来肯定会导致混淆。

您的noSpace值是多少?而且你的代码格式也很糟糕。为每个代码语句使用单独的一行。您最好给我们一个示例来说明您想要什么。支持@KudoCC comment,您能用一个示例更新您的问题吗?-(iAction)addSpace:(id)sender{//此处noSpace是一个文本框NSMutableString*string1=[NSMutableString-stringWithString:self.noSpace.text];//这就是我要找的…[string1-insertString:@”“atIndex:2];//在withSpace-textBox.self.withSpace.text=string1;中显示noSpace-textBox的结果]要显示空格还是要插入特定的空格字符?我想在字符串之间加一个空格,如果字符串的长度等于4,则应在字符串之间加一个空格。-(iAction)addSpace:(id)sender{//此处noSpace是文本框NSMutableString*string1=[NSMutableString-stringWithString:self.noSpace.text];//这就是我要找的…[string1-insertString:@”“atIndex:2];//在withSpace-textBox.self.withSpace.text=string1;中显示noSpace-textBox的结果]
- (IBAction)addSpace:(id)sender {
//here noSpce is a textbox in which i will enter some value
    NSString *one=self.noSpace.text;

    if (one.length==4)
    //if the length of the string is equal to four then it should put a whitespace 
    //in between the string.
    {
        NSString *blank=@"  ";
        NSString *two=[blank. stringByAppendingString:one,index(2)];
        NSString *new=two;


 //here withSpace is another textbox in which i want to show the expected result
            self.withSpace.text=new;
        }

//this really does not work for me
- (IBAction)addSpace:(id)sender
{
//here noSpace is a textBox 
    NSMutableString *string1=[NSMutableString stringWithString:self.noSpace.text];
    //this was what i was looking for. . . 
    [string1 insertString:@" " atIndex:2];
    //showing result of noSpace textBox in withSpace textBox.
    self.withSpace.text=string1;

}