Backslash is used to represent special characters like "
on a NSString
literal. So, actually the str2
string doesn't have any backslash, while the summary
string do (added by stringByReplacingOccurrencesOfString:withString:
).
Back slash issue while comparing two strings
Question
I am getting some string from service
<iframe width="560" height="314" src="http://www.youtube.com/embed/oWeXKVioM34" frameborder="0" allowfullscreen></iframe>
I just replaced the string like this
summary = [summary stringByReplacingOccurrencesOfString: @"\"" withString:@"\\\""];
NSString *str2=@"<iframe width=\"560\" height=\"314\" src=\"http://www.youtube.com/embed/oWeXKVioM34\" frameborder=\"0\" allowfullscreen></iframe>"// this is my expected string which i got in console area for summary.
I am getting exactly in console area but if I compared the strings
if([str2 isEqualToString:summary])
{
NSLog(@"same......");
}
else{
NSLog(@"notsame ......");
}
I wondered I am getting notsame
as output even they appear same
in console area. Then I calculated the length for summary it is 129 and for str2 it is 121.
then I got that there is a problem of backslash because I added 8 slashes,then what to do to get same output.
any help would be really appreciated. thank you.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow