SQLITE Insert returns value with extra line
While parsing the data I insert the data in sqlite. But for some reason when I run the SELECT query it returns me with extra line and a tab space. When I write this query it inserts the data correctly but with extra spaces.
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
if([elementName isEqual:@"root"]) {
}
else if([elementName isEqualToString:@"value"]) {
value = [[Value alloc] init] ;
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if(!trueValue)
trueValue = [[NSMutableString alloc] initWithString:string];
else{
[trueValue appendString:string];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if([elementName isEqualToString:@"root"])
return;
if([elementName isEqualToString:@"value"]) {
NSString *sqlQuery = [NSString stringWithFormat:@"INSERT OR REPLACE INTO DETAIL(ID,KEY, TITLE) VALUES ('%@','%@','%@');", key, parent_key, title];
const char *insert_sql = [sqlQuery UTF8String];
sqlite3_exec(db, insert_sql, NULL, NULL, NULL);
}
else if([elementName isEqualToString:@"key"])
[value setValue:finalValue forKey开发者_运维技巧:elementName]
[trueValue release];
trueValue = nil;
}
How can I REPLACE the extra spaces basically like : "\n\t\t\t" with "" before this statement for all the rows?
I had a similar problem which I fixed by trimming out all the whitespace characters like this:
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if(!trueValue)
trueValue = [[NSMutableString alloc] initWithString:[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
else
[trueValue appendString:[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
}
Try this:
[string stringByReplacingOccurrencesOfString:@"\n\t\t\t" withString:@""]
精彩评论