[英]How to compare char* and NSString?
Hi I am comparing UserName(char*) from database and UserName(NSString*) from UITextField. 您好我正在比较来自数据库的UserName(char *)和来自UITextField的UserName(NSString *)。 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. 但它永远不会进入循环,虽然我给出与数据库中相同的UserName。
Assume following is the NSString you have. 假设您拥有以下NSString 。
NSString *userName = @"SomeOnesName";
Get the C-String from DB and convert it to NSString . 从DB获取C-String并将其转换为NSString 。
NSString *userNameFromDB = [NSString stringWithCString:sqlite3_column_text(statement, 0) encoding:NSUTF8StringEncoding];
Now the comparison. 现在进行比较。
if ([userName isEqualToString:userNameFromDB]) {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.