在iphone上写这个的最好方法

时间:2010-07-08 09:55:13

标签: iphone

这是我想要的输出 “SELECT * FROM wateat_tbl,其中名称如'%love%'或desc like'%love%'”;

其中爱是使用 r进入的文字 现在我想以有效的方式写这个 现在我正在做这个蹩脚的代码

    myStringPrt1=@"SELECT * FROM wateat_tbl where name like '%"

    NSString *trimmedString1 = [myStringPrt1 stringByTrimmingCharactersInSet:
                                [NSCharacterSet whitespaceAndNewlineCharacterSet]];

    myStringPrt2=UserText;// user input LOVE
    NSString *myStringPrt3=@"%' or desc like '%";
    NSString *myStringPrt4=@"%'";


    trimmedString1=[trimmedString1 stringByAppendingString:myStringPrt2];

    trimmedString1=[ trimmedString1 stringByAppendingString:myStringPrt3];
    trimmedString1=[ trimmedString1 stringByAppendingString:myStringPrt2];
    trimmedString1=[ trimmedString1 stringByAppendingString:myStringPrt4];
    NSLog(@"My string is  now =  %@", trimmedString1);

1 个答案:

答案 0 :(得分:0)


NSString* SQL_statement = [NSString stringWithFormat:@"SELECT * FROM wateat_tbl where name like '%@%%' or desc like '%%%@'", UserText, UserText];