Hi, I am having problems with comparing an NSString with a string from an array. I used the following one line of code to try and compare the 2 with an if statement:
if ([x isEqualToString:guidString])
Now I am not sure if it is because one is an NSString and one is an NSMutableString or if I am just missing something. (I do know that the array does have the correct information in it).
int totalArrayElements = [arrayArticleGUID count];
int countGuidRow = 0;
NSString *guid = nil;
The way you used isEqualToString in your first snippet is good, and it should work even is one or both is a mutable string. I assume it's always returning false? That could happen if one or both string is nil. Did you try logging the strings to see what you're really getting?
Code:
NSLog( @"x is: %@ ", x);
NSLog( @"guidString is: %@ ", guidString);
if ([x isEqualToString:guidString]) {
countGuidRow = scanArrayElements;
}
Thank you very much! There was a trailing new line (\n) at the end of all of my array elements. I wasnt checking the log because if I took that array element and used it to load a UIWebView, XCode was ignoring the trailing character. So laziness on my part so I appreciate it a lot!
Another problem came up though that I am looking for the answer for and will post when I find it. When I use:
So I ended up working around it for now. I created an NSString and made the NSString equal the NSMutableString, and then replaced the characters. I know this isnt good code but I have to move on for now. When/If I find the correct way I will post it on here.
I did find what I think is the correct code though, but it was crashing my program (I think because I was appending all original elements of the array in the loop permanently, which also crashed my program when I tried to write an external loop to first change all of the elements).
The method you're using, stringByReplacingOccurrencesOfString, creates a new NSString. It does not modify your mutable string. The compiler error comes because you're pointing your pointer, which is supposed to point to an NSMutableString, at the NSString that gets returned. You might be leaking your mutable string too, since you no longer have a pointer to it.
Look for "replaceOccurrencesOfString: withString: options: range:" , which is an NSMutableString method that actually modifies your mutable string instead of creating a new string.
Thank you very much! There was a trailing new line (\n) at the end of all of my array elements. I wasnt checking the log because if I took that array element and used it to load a UIWebView, XCode was ignoring the trailing character. So laziness on my part so I appreciate it a lot!
Another problem came up though that I am looking for the answer for and will post when I find it. When I use: