How to compare textfield.text and coredata attribute? - core-data

Here is my code..
NSLog(#"%#", [textField text]);
NsLog(#"%#", entity.attribute);
The log shows me The values
123 and 123 as the correct values..
But this code is not works
If([textField text] == entity.attribute) NSLog(#"Correct!");
The log "Correct!" is not shown..
What's the problem?? Help plz

You are comparing NSString* pointers, not their values... they are different objects.
If both are non-nil (might want to check for that), the following will work:
If([[textField text] compare:entity.attribute]==NSOrderedSame) NSLog(#"Correct!");

Related

Compare nsurl or string in swift 2

I am comparing two nsurl which are same but if condition is failing
if (url.absoluteString == self.currentPlayer?.currentAssetURL())
values
(lldb) po url.absoluteString
"Optional(https://a.t/y.mp3)"
(lldb) po self.currentPlayer?.currentAssetURL()
▿ Optional("https://a.t/y.mp3")
- Some : "https://a.t/y.mp3"
both urls are same but if condition is failing.
Please suggest.
Thanks in advance!
I found the answer. The problem was optional added inside the string and outside the string.
I fixed it.

String comparison in groovy script not working

I am trying to compare 2 Strings in groovy script. both have same value but they are in different case while m trying compare it using equalsIgnoreCase still it is showing not equals.
Here is my code:
def st1=Austin
def ct=AUSTIN
if(st1.equalsIgnoreCase(ct)){
log.info "city equals"
}
else{
log.info "not eq"
}
it's printing "not eq".I tried toString() and toUpperCase methods.Plz help me out
Sorry for the erroneous post. I got my problem I was working with db. it gives me value with some extra spaces. So my comparison was not working. later I used
trim()
to remove it.

Locating and removing an esc sequence objective-c

I'm trying to remove an escape sequence (\p) from selected strings (for reuse in other places in my code). I want to create a separate object that holds that cleaned up string. Like this
(pseudo code)
NSString *stringWithEscSequence = anEdgewoodSecretPlace.placeName;
NSString *stringWithoutEscSequence = [removeTheEscSequenceP stringWithEscSequence];
(where removeTheEscSequenceP is what I'm trying to figure out how to do)
....
I played with NSString formats and I found related questions at
Position of a character NSString
and
how to replace one substring with another in Objective C?
I can break out the substring that follows the escape sequence use ideas from the second posting. So I thought then I should try to locate the actual index of the escape sequence. But I can't figure out how to do that. Also I think there is probably a less messy, more straightforward way to do this, that I'm not thinking of.
I was playing around with the first posting ideas, though I knew that I was in a kind of primitive mode. But as soon as I attempt to replace "ABCD" with "\". I get an error 'Missing terminating """ = except if I put the ABCD string back in I'm not missing any quotes. I think it's because of the special nature ofo the \ character.
Even if I could figure out how to search for the "\" and then a "p" following that, I don't think that's really the best way to approach this
NSCharacterSet *charSet = [NSCharacterSet characterSetWithCharactersInString:#"ABCD"];
NSRange range2 = [testCleanString rangeOfCharacterFromSet:charSet];
if (range2.location == NSNotFound) {
NSLog (#"Didn't find esc sequence");
} else {
NSLog (#"range.location is %lu",(unsigned long)range2.location );
}
You could try with this:
NSString* stringWithoutEscSequence = [stringWithEscSequence stringByReplacingOccurrencesOfString:#"stringToRemove" withString:#"replacement"];
If you want to replace multiple characters you could do:
NSCharacterSet* toRemove = [NSCharacterSet characterSetWithCharactersInString:#"\n\p\t"];
NSString* stringWithoutEscSequence = [[stringWithEscSequence componentsSeparatedByCharactersInSet:toRemove] componentsJoinedByString: #""];

iOS comparing NSDictionaries in Arrays

I'm trying to find the index of an NSDictionary in an Array with NSDictionaries, but having problems with the encoding of the two.
Array a: is downloaded from a webserver (as a csv-string) and then converted into an Array of dictionaries.
Array b: is loaded with [NSArray arrayWithContentsOfFile] from a plist.
The dictionaries and arrays look good, but [indexOfObject] doesn't give me any results.
By outputting the data to the console, I found out that German Umlauts are encoded differently.
Array a: shows the character «ä» as \U00c3\U00a4
Array b: shows the character «ä» as \U00e4
So I guess that's why the function returns a NSNotFound.
I tried to cast the strings in many different ways, with no result...
Interestingly, the function used to work...
Any Ideas?
[EDIT]
Well, it turns out I didn't process the data coming from the server correctly.
I had to change this
NSString *dataStr=[[NSString alloc] initWithData:self.receivedData encoding:NSASCIIStringEncoding];
into this:
NSString *dataStr=[[NSString alloc] initWithData:self.receivedData encoding:NSUTF8StringEncoding];

Accessing data in a nested matrix

This one has me stumped, and none of the other related questions here have given me clues. I'm using regexp to parse a string. When I print t afterward, it looks something like this:
t =
{
[1,1] =
{
[1,1] = HELLO
[1,2] = 1234
}
}
I would like to be able to pull out the HELLO and 1234. I've tried all different ways to access the elements in the nested matrix, but am not having any luck. I can't even find it in the Octave documentation! Can someone please help me out? Thank you!
I believe this is the answer -- regexp doesn't return a matrix, it returns a cell array. I just have to use {} to get access to the data. i.e. to get HELLO, it is t{1}{1}. To get 1234 it is t{1}{2}.
http://www.gnu.org/software/octave/doc/interpreter/Cell-Arrays.html

Resources