Ravi Nalawade
Ravi Nalawade

Reputation: 37

How to compare char* and NSString?

Hi I am comparing UserName(char*) from database and UserName(NSString*) from UITextField. How to do this. Following is my code

if ([UserName isEqual:(char *)sqlite3_column_text(statement, 0)]) {

    NSLog(@"User Already Exists.");
    flag = YES;
    return;
}

But it never goes into loop though I give same UserName as in Database.

Upvotes: 3

Views: 1275

Answers (1)

EmptyStack
EmptyStack

Reputation: 51374

Assume following is the NSString you have.

NSString *userName = @"SomeOnesName";

Get the C-String from DB and convert it to NSString.

NSString *userNameFromDB = [NSString stringWithCString:sqlite3_column_text(statement, 0) encoding:NSUTF8StringEncoding];

Now the comparison.

if ([userName isEqualToString:userNameFromDB]) {

Upvotes: 9

Related Questions