iphone - 从 Web 输出中提取表格

标签 iphone objective-c xcode ios string

我能够将网页作为长字符串拉入我的代码中。现在我想删除 <table> 之前的所有内容标签,并在 <table> 之后标签 - 所以我只保留表格本身。

我正在考虑使用 NSScanner 或 regexp。您认为哪个更有效/更易于代码管理?该页面还可能(将来)包含两个表,我想提取每个表(一个接一个)以在我的 View 中显示。

有什么想法吗?

提前致谢!
Kolya

最佳答案

您好,您可以使用此代码

 - (NSMutableArray *)stringFilter:(NSString *)targetString {

        NSScanner *theScanner;
        NSString *text = nil;

        theScanner = [NSScanner scannerWithString: targetString];

        while ([theScanner isAtEnd] == NO) {

            [theScanner scanUpToString:@"<table>" intoString:NULL] ; 

            [theScanner scanUpToString:@"</table>" intoString:&text] ;

           [tempArray addObject:text];

        } 

        return tempArray;

    }

临时数组将包含表标记 got help from this site 中的所有字符串

关于iphone - 从 Web 输出中提取表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6079266/

相关文章:

iphone - iphone MKMapKit 的奇怪行为

iphone - 从 UIView 创建 UIImage 时出现非空无效上下文错误

ios - 从内存中删除 NSString

ios - 更改 MPVolumeView iPad 弹出框大小

ios - 在我的 iPhone 中显示当前位置

ios - 复制/粘贴UIMenuItem不在我的所有应用程序中显示

iphone - 在重新验证 iOS 自动续订订阅时,我应该使用旧的收据数据吗?

ios - Xcode 7 GM 缺少 iOS 7 模拟器

iphone - 使用 AirDrop 发送和接收文件

iPhone 表单样式