how to remove quote and slash from string in iphone
Hi friends... I am using regular expression so I get string but with double quote and slash but I dont want that. I want string value without slash and double quotes. I try this I'm but not getting proper answer.
I get error after running application [/Users/pradeepyadav/Desktop/RegexKitLiteDemo/Classes/RegexKitLiteDemoAppDelegate.m:108:0 /Users/pradeepyadav/Desktop/RegexKitLiteDemo/Classes/RegexKitLiteDemoAppDelegate.m:108: error: incompatible block pointer types initializing 'void (^)(struct NSString *, NSUInteger, BOOL *)', expected 'void (^)(struct objc_object *, NSUInteger, BOOL *)
I get this error line
Second one is this : [/Users/pradeepyadav/Desktop/RegexKitLiteDemo/Classes/RegexKitLiteDemoApp开发者_Python百科Delegate.m:105:0 /Users/pradeepyadav/Desktop/RegexKitLiteDemo/Classes/RegexKitLiteDemoAppDelegate.m:105: warning: 'NSString' may not respond to '+stringByTrimmingCharactersInSet:
I get this error line [webData length] encoding:NSUTF8StringEncoding];
//NSLog(@"%@",loginStatus);
[connection release];
//
NSString *regexString = @"Stations\\[""(.*)""\\] = new Station\\((.*)new Array\\((.*)\\)\\);"; //@"Stations\\[""(.*)""\\] = new Station\\((.*)\\);"; //@"Stations\[""(.*)""\] = new Station\({[\,,2}(.*)new Array\((.*)\)\);"; //@"<a href=([^>]*)>([^>]*) - ";
matchArray = [loginStatus arrayOfCaptureComponentsMatchedByRegex:regexString];
NSMutableArray *newArray = [[NSMutableArray alloc] initWithCapacity:[matchArray count]];
//NSCharacterSet *charactersToRemove = [NSCharacterSet punctuationCharacterSet];
[matchArray enumerateObjectsUsingBlock:^(NSString *aString, NSUInteger idx, BOOL *stop)
{
NSString *newString = [NSString stringByTrimmingCharactersInSet:[NSCharacterSet punctuationCharacterSet]];//#############
[newArray insertObject:newString atIndex:idx];
NSLog(@"matchArray: %@", matchArray);
}];//******************
//NSLog(@"matchArray: %@", matchArray);
lstAirports = [[NSMutableArray alloc] initWithCapacity:[matchArray count]];
for (int i = 0; i < [matchArray count]; i++) {
airport *air=[[airport alloc]init];
//code
air.Code = [[matchArray objectAtIndex: i] objectAtIndex: 1];
NSLog(@"air.Code: %@\n",air.Code);
//name
NSString *temp=[[matchArray objectAtIndex: i] objectAtIndex: 2];
NSArray *arrParts=[temp componentsSeparatedByString:@""","];
//air.Name=arrParts[2];
air.Name=[arrParts objectAtIndex:2];
NSLog(@"air.Name: %@\n",air.Name);
//destination airports
temp=[[matchArray objectAtIndex: i] objectAtIndex: 3];
arrParts=[temp componentsSeparatedByString:@","];
air.DestinationAirports =arrParts;
NSLog(@"air.DestinationAirports: %@\n",air.DestinationAirports);
[lstAirports addObject: air];
NSLog(@"lstAirports: %@\n",lstAirports);
}
//[webData release];
}
please some help me fast it's vital for me
You don't need RegExp to remove occurrences of string in NSString.
See the example below, i hop it will help you:
NSString *str = @"fdf\"fdsfdsf\"fsdfsf/fsdfsdfsf\\fsdfsdf\\fsdffsd//fsdfsf\"fsdf/\\\"";
str = [str stringByReplacingOccurrencesOfString:@"\"" withString:@""];
str = [str stringByReplacingOccurrencesOfString:@"\\" withString:@""];
str = [str stringByReplacingOccurrencesOfString:@"/" withString:@""];
NSLog(@"%@", str);
Check for the usage of
stringByReplacingOccurrencesOfString:withString
:
in
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html.
You can replace them with "" characters.
精彩评论