2

I am reading CSV file in my application.

I want to replace two different strings and print as one line. for example:

string1#$string2#$string3####string4

I want to replace #$ with , and #### with \n

and want to show the result on a UILabel.

1
  • you can try this.. NSString *completeString = [string stringByReplacingOccurrencesOfString:@"#$ "withString:@"\n"]; Commented Jan 8, 2013 at 12:12

3 Answers 3

4

You can use stringByReplacingOccurrencesOfString:withString: method, like this:

NSString *orig = "string1#$string2#$string3####string4";
NSString *res = [orig stringByReplacingOccurrencesOfString:@"#$" withString:@" "];
res = [res stringByReplacingOccurrencesOfString:@"####" withString:@"\n"];

Note that the original string does not get changed: instead, a new instance is produced with the replacements that you requested.

Sign up to request clarification or add additional context in comments.

Comments

0

use

String = [String stringByReplacingOccurrencesOfString:@"#$" withString:@","];
String = [String stringByReplacingOccurrencesOfString:@"####" withString:@"\n"];

And then

yourLabel.text=String;

Comments

0

Try this

NSString *string = @"####abc#$de";
string = [string stringByReplacingOccurrencesOfString:@"####" withString:@"\n"];
string = [string stringByReplacingOccurrencesOfString:@"#$" withString:@","];

Hope it helps you

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.