美文网首页
Vickate_将.txt文件转成字符串String

Vickate_将.txt文件转成字符串String

作者: Vickate | 来源:发表于2018-07-09 14:19 被阅读0次

    Began

    • 不逼逼,直接代码
    NSMutableString *str = [[NSMutableString alloc] init];
        NSString *protocolPath = [[NSBundle mainBundle] pathForResource:_textFiel ofType:@"txt"];
        xmlDocPtr doc = xmlReadFile([protocolPath UTF8String], NULL, XML_PARSE_RECOVER);
        if (!doc)
        {
            return nil;
        }
        xmlNodePtr root = xmlDocGetRootElement(doc);
        if (root)
        {
            for (xmlNodePtr curNode = root->children; NULL != curNode; curNode = curNode->next)
            {
                if(strcmp((char *)curNode->name, "string") == 0)
                {
                    [str appendString:[NSString stringWithCString:(const char*)xmlNodeGetContent(curNode) encoding:NSUTF8StringEncoding]];
                    [str appendString:@"\n"];
                }
            }
        }
        xmlFreeDoc(doc);
        return str;
    

    End

    相关文章

      网友评论

          本文标题:Vickate_将.txt文件转成字符串String

          本文链接:https://www.haomeiwen.com/subject/wjzzuftx.html