Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iphone中为正则表达式上的字符串分离组件_Iphone_Objective C - Fatal编程技术网

如何在iphone中为正则表达式上的字符串分离组件

如何在iphone中为正则表达式上的字符串分离组件,iphone,objective-c,Iphone,Objective C,朋友们好, 我在这里做规则,我创建所有,我存储在数组中,并在控制台中打印,但我也在组中给出,但当我给出由字符串分离的组件时,不起作用,为什么我在执行此代码时出错?我的应用程序将崩溃并记录消息打印此消息:- [__NSCFArray componentsSeparatedByString:]: unrecognized selector sent to instance 0x4e283a0 2011-09-12 14:05:48.400 RegexKitLiteDemo[10576:207

朋友们好,

我在这里做规则,我创建所有,我存储在数组中,并在控制台中打印,但我也在组中给出,但当我给出
由字符串分离的组件时,
不起作用,为什么我在执行此代码时出错?我的应用程序将崩溃并记录消息打印此消息:-

[__NSCFArray componentsSeparatedByString:]: unrecognized selector sent to instance 0x4e283a0
    2011-09-12 14:05:48.400 RegexKitLiteDemo[10576:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFArray componentsSeparatedByString:]: unrecognized selector sent to instance 0x4e283a0
这是我的密码请有人帮我找到正确的方向

-(void)sendRequest

{
    // create the request
    NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.bookryanair.com/SkySales/FRSearch.aspx"]
                                              cachePolicy:NSURLRequestUseProtocolCachePolicy
                                          timeoutInterval:60.0];

    NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    if (theConnection) {

        webData = [[NSMutableData data] retain];
        NSLog(@"%@",webData);
    } else {
        // inform the user that the download could not be made
    }   

}

/// this for checking is that Sync is work or not 

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{   
    [webData setLength: 0]; 


} 

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{         
    [webData appendData:data]; 

} 

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 
{     
    [connection release];  
    [webData release]; 
    NSLog(@"Connection failed! Error - %@ %@",
          [error localizedDescription],
          [[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]);

} 

-(void)connectionDidFinishLoading:(NSURLConnection *)connection 
{      
    loginStatus = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding]; 



    [connection release];

    NSString *regexString = @"Stations\\[""(.*)""\\] = new Station\\((.*)new Array\\((.*)\\)\\);"; 
    matchArray = [loginStatus arrayOfCaptureComponentsMatchedByRegex:regexString];




    NSLog(@"matchArray: %@", matchArray);


    group = [[NSMutableArray alloc] initWithCapacity:[matchArray count]];

    for (int i = 0; i < [matchArray count]; i++) {

         NSString *temp = [[matchArray objectAtIndex: i] componentsSeparatedByString: @","];

        [group addObject: temp];
    NSLog(@"group: %@", group);  
    }   
} 
-(无效)发送请求
{
//创建请求
NSURLRequest*theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@]http://www.bookryanair.com/SkySales/FRSearch.aspx"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
NSURLConnection*连接=[[NSURLConnection alloc]initWithRequest:theRequest委托:self];
if(连接){
webData=[[NSMutableData]保留];
NSLog(@“%@”,网络数据);
}否则{
//通知用户无法进行下载
}   
}
///这用于检查同步是否有效
-(void)连接:(NSURLConnection*)连接DidReceiverResponse:(NSURResponse*)响应
{   
[webData setLength:0];
} 
-(void)连接:(NSURLConnection*)连接didReceiveData:(NSData*)数据
{         
[webData:data];
} 
-(无效)连接:(NSURLConnection*)连接失败错误:(NSError*)错误
{     
[连接释放];
[网络数据发布];
NSLog(@“连接失败!错误-%@%”),
[错误本地化描述],
[[error userInfo]objectForKey:nsurErrorFailingUrlStringErrorKey]);
} 
-(无效)连接IDFinishLoading:(NSURLConnection*)连接
{      
loginStatus=[[NSString alloc]initWithBytes:[webData mutableBytes]长度:[webData长度]编码:NSUTF8StringEncoding];
[连接释放];
NSString*regexString=@“Stations\\[”“(.*)”\\]=新的Station\(.*)新的数组\(.*)\\)\;“;
matchArray=[loginStatus arrayOfCaptureComponentsMatchedByRegex:regexString];
NSLog(@“matchArray:%@”,matchArray);
组=[[NSMutableArray alloc]initWithCapacity:[matchArray count]];
对于(int i=0;i<[matchArray计数];i++){
NSString*temp=[[matchArray objectAtIndex:i]组件由字符串分隔:@“,”];
[组addObject:temp];
NSLog(@“组:%@”,组);
}   
} 

将componentsSeparatedByString方法应用于NSString,并返回和NSArray

- (NSArray *)componentsSeparatedByString:(NSString *)separator
e、 g.
NSArray*array=[aString componentsSeparatedByString:@“,”]

因此,首先,在您的代码中,以下行是错误的

NSString *temp = [[matchArray objectAtIndex: i] componentsSeparatedByString: @","];

如果您试图将NSString对象的NSArray转换为一个由逗号分隔的字符串,请尝试以下方法:

NSString *temp = [[matchArray objectAtIndex:i] componentsJoinedByString:@","];
对数组调用的
componentsJoinedByString
将从数组组件返回单个字符串


对字符串调用ComponentSeparatedByString
将返回由字符串组件组成的数组(取决于分隔符)

当调用方法ComponentSeparatedByString的实例无效时,也会遇到u接收到的错误。在这里,由于您已经使用NSLog打印MAtcharray,我建议您检查它是否正确打印。另外,由于您正试图逐个元素访问并调用组件。。。。方法进行检查,通过逐个元素打印来确认它是否确实存在

你能给我详细的信息吗?我不明白你的意思。请帮助我的朋友,如何为这个确定的家伙编码,我可以问你具体不明白的是什么吗?这一行中的错误是“componentsSeparatedByString”的输出是NSArray而不是NSString。您还应该查看NSString类参考以了解有关此的更多信息。NSArray*arr=[someString Components由字符串分离:@“,”;意味着componentsSeperateByString函数返回NSArray对象而不是string@Madhu解释。