how to compare 2 strings - iphone

i have two strings initialised with using nsstring *name1,*name2...
how to compare these

if([name1 isEqualToString:name2]){
NSLog("These are the same name");
}
The best place for API features like this is the Apple documentation

Related

Foursquare venue's category photos issue

i am having trouble about json part of venues, in this picture i am trying to take the prefix and suffix, i am putting size between them but my problem is when i try to put them together the link of prefix + size + suffix comes like this -> i am taking prefix and suffix in seperate NSMutableArray's but when i try to join them together it's not working. and here is my way to join them.
where am i doing this wrong?
Are you sure that your objects in the imagePrefix and imageSuffix arrays are actually strings? Because judging from your logs it looks as if you're trying to concatenate two arrays and a string. If you let us know what is actually in those arrays you might get more helpful answers. You must be doing some conversion/manipulation from the original JSON, as in the API they get returned as dictionary items not arrays.
On a unrelated note, consider using fast enumeration (for id item in array) rather than writing out the for statement as you've done. Generally speaking it's also much better to post your code as text using markdown syntax rather than images: makes it much harder to copy/paste your code into an answer.
so thanks to "Matthias Bauch" i figured it out and here is my answer for my own question :)
for (int e = 0; e<=[imagePrefix count]-1; e++) {
NSLog(#"%#b_32%#", [[imagePrefix objectAtIndex:e] objectAtIndex:0], [[imageSuffix objectAtIndex:e] objectAtIndex:0]);
}
Thanks guys!

Localizing dynamic NSString

Going through number of examples regarding to NSLocalizedString, what I found was we need to pre-define all the string in Localized.string file for what-ever language you want to localize. But, is it possible to localize dynamic string. My idea was, I am displaying few text in UILabel that i get after web request. It means the string is now dynamic in nature.
Declare in Localizable.strings
"SAMPLE_LOCALIZE_STRING" = "This is sample dynamic localize string for %#.";
Use it like this
NSString *dynamicStr = #"Test";
label.Text = [NSString stringWithFormat:NSLocalizedString(#"SAMPLE_LOCALIZE_STRING", nil), dynamicStr];
If those strings are fixed ones (I mean a limited number of options) then pre-store them in the localized string file.
If not, I would suggest to add a parameter to your request that would indicate the language and then the server would return string in that language.
I have handled this situation as follows,
Include language in the request. For ex: http://yourIp/language/notesandcondition
The webservice should be designed to handle for different languages.
[NSString stringWithFormat:NSLocalizedString(#"Table View Cell Row %d", #""), indexpath.row];

Web services with JSON Parsing

In my app Web services are created in dot net and i am consuming those and I am getting response.In that all the fields like company,type,location everything are strings and there is no problem with this..And there is one more field called Exhibit number actually it is a Integer but they are created as string only.While I am displaying this it is showing zero instead of that number.. Here is my code...
//Storing into Array
[SurveyFilesArray addObject:[NSDictionary dictionaryWithObjectsAndKeys:[dic objectForKey:#"FileName"],#"FileName",[dic objectForKey:#"ExibhitNumber"],#"ExhibitNumber",[dic objectForKey:#"Description"],#"Description",[dic objectForKey:#"FileQuality"],#"FileQuality",nil]];
//Retrieving from Array..
NSLog(#"???%#???",[NSString stringWithFormat:#"%d",[[[SurveyFilesArray objectAtIndex:indexPath.row]objectForKey:#"ExibhitNumber"]intValue]]);
NSLog(#"%d",[[[SurveyFilesArray objectAtIndex:indexPath.row]objectForKey:#"ExibhitNumber"]intValue]);
You have typos in your code.
In the order of your code:
Ex-ib-hit-Number
Ex-hib-it-Number
These are 2 different strings.
In your example code you save it correctly written as Ex-hib-it. But you try to access it with ex-ib-hit afterwards. This cannot work.

supporting internationalization for NSString's

I have a bunch of the following line of code:
[NSString stringWithFormat:#"%# and %#", subject.title, secondsubject.title];
[NSString stringWithFormat:#"%# and %d others", subject.title, [newsfeeditem count] - 1];
and a lot more in the app. Basically I am building a news feed style like facebook where it has string constants. blah liked blah. Where/how should I do these string constants so it's easy to do for internationalization? Should I have a file just for storing string constants?
See the String Resources section of the Resource Programming Guide. The key section for this particular problem is "Formatting String Resources."
You'd have something like:
[NSString stringWithFormat:NSLocalizedString(#"%1$# and %2$#", #"two nouns combined by 'and'"),
subject.title, secondsubject.title];
The %1$# is the location of the first substitution. This lets you rearrange the text. Then you would have string resource files like:
English:
/* two nouns combined by 'and' */
"%1$# and %2$#" = "%1$# and %2$#";
Spanish:
/* two nouns combined by 'and' */
"%1$# and %2$#" = "%1$# y %2$#";
You need to be very thoughtful about these kinds of combinations. First, you can never build up a sentence out of parts of sentences in a translatable way. You're almost always need to translate the entire message in one go. What I mean is that you can't have one string that says #"I'm going to delete" and another string that says #"%# and %#" and glue them together. The word order is too variable between languages.
Similarly, complex lists of things can cause all kinds of headaches due to various agreement rules. Some languages have special plural rules, gender agreements, and similar issues. As much as possible, keep your messages simple, short, and static.
But the above tools are very useful for solving the problem you're discussing. See the docs for more details.

Parsing XML, details and attributes, iphone

I'm not sure about parsing an xml with attributes. have seen a similar question here
But it shows to get an attribute of intValue. But i need to get the attributes of string type,How to do that?? Images of xml and the relevant portions are given in the following links
Click here for xml and here for required data
This answer to the linked question should work for you as well. The contents of attributeDict are already NStrings. All that is going on extra in the linked answer that they are calling the intValue method on the returned NSString to parse that string into an int. In your case, you don't need this little bit of an extra step. If you just do this:
NSString * stringValue = [attributeDict objectForKey:#"attribute"];
you'll have the value of the attribute called "attribute" in a string.