How to choose position to print a string in a text?

0

I'm developing an app where the user can choose between a text, the position where the output value of a string should be printed.  Example:  Normally when we print a string in the middle of a text we do this:

 NSLog (@" Um texto com:%@", minhaVariavelString);

Or when we use a UITextField:

_meuTextField.text = [NSString stringWithFormat: @"Meu valor:%@.", minhaString];

Keeping the position of %@ fixed.

But I want to be able to give the user the ability to change the output position of the string in a text composition screen when the app is running.

    
asked by anonymous 16.03.2015 / 19:48

1 answer

2

Just create a NSMutableString and use the insertString:AtIndex: method.

Example:

NSMutableString *vitima = [NSMutableString stringWithString:@"Minha String Legal"];
NSLog(@"%@", vitima); //Imprime "Minha String Legal"
[vitima insertString:@"Não tão " atIndex:13];
NSLog(@"%@", vitima); //Imprime "Minha String Não tão Legal"
    
16.03.2015 / 23:44