Monika Patel
Monika Patel

Reputation: 2375

How to append substring into main string?

My original string is : Låt den jäsa tifgdfgfll dubbel storlek ungdfgdfder en handduk endtimer dfgsdg fgsdfg hello ho hi Låt den jäsa till dubbel storlek undegdfgr en handduk endtimer heouu hiy hinl Låt den jäsa till dubbel stofgdfgrlek under en hfdgdfndduk endtimer jijfr ii iuwii Låt den jäsa till dugdfgbbel storgdfglek under en handdgdfguk endtimer dfdf Låt den jäsa tfdgfdill dubbel storgdfglek under en handduk endtimer

And i want to add "iOS" before "Låt" and add "objective c" after "endtimer" in original string.

So i want this output string : iOS Låt den jäsa tifgdfgfll dubbel storlek ungdfgdfder en handduk endtimer objective c dfgsdg fgsdfg hello ho hi iOS Låt den jäsa till dubbel storlek undegdfgr en handduk endtimer objective c heouu hiy hinl iOS Låt den jäsa till dubbel stofgdfgrlek under en hfdgdfndduk endtimer objective c jijfr ii iuwii iOS Låt den jäsa till dugdfgbbel storgdfglek under en handdgdfguk endtimer objective c dfdf iOS Låt den jäsa tfdgfdill dubbel storgdfglek under en handduk ca endtimer objective c

Upvotes: 1

Views: 80

Answers (2)

Chetan
Chetan

Reputation: 2124

An option:

NSString *string = @"Låt den jäsa tifgdfgfll dubbel storlek ungdfgdfder en handduk endtimer dfgsdg fgsdfg hello ho hi Låt den jäsa till dubbel storlek undegdfgr en handduk endtimer heouu hiy hinl Låt den jäsa till dubbel stofgdfgrlek under en hfdgdfndduk endtimer jijfr ii iuwii Låt den jäsa till dugdfgbbel storgdfglek under en handdgdfguk endtimer dfdf Låt den jäsa tfdgfdill dubbel storgdfglek under en handduk endtimer";

NSString *mainString = [NSString stringWithFormat:@"%@ %@ %@", @"iOS", string, @"objective c"];

OR

NSString *string = @"Låt den jäsa tifgdfgfll dubbel storlek ungdfgdfder en handduk endtimer dfgsdg fgsdfg hello ho hi Låt den jäsa till dubbel storlek undegdfgr en handduk endtimer heouu hiy hinl Låt den jäsa till dubbel stofgdfgrlek under en hfdgdfndduk endtimer jijfr ii iuwii Låt den jäsa till dugdfgbbel storgdfglek under en handdgdfguk endtimer dfdf Låt den jäsa tfdgfdill dubbel storgdfglek under en handduk endtimer";

NSString *mainString = @"iOS ";

mainString = [mainString stringByAppendingString:string];

mainString = [mainString stringByAppendingString:@" objective c"];

Upvotes: 2

Jamil
Jamil

Reputation: 2999

Try with this

NSString *appendString = [yourString stringByReplacingOccurrencesOfString:@"Låt" withString:@"iOS Låt"];
appendString = [appendString     stringByReplacingOccurrencesOfString:@"endtimer" withString:@"endtimer objective c"];

Upvotes: 4

Related Questions