<legend id='MhAlm'><style id='MhAlm'><dir id='MhAlm'><q id='MhAlm'></q></dir></style></legend>
    <tfoot id='MhAlm'></tfoot>
  • <i id='MhAlm'><tr id='MhAlm'><dt id='MhAlm'><q id='MhAlm'><span id='MhAlm'><b id='MhAlm'><form id='MhAlm'><ins id='MhAlm'></ins><ul id='MhAlm'></ul><sub id='MhAlm'></sub></form><legend id='MhAlm'></legend><bdo id='MhAlm'><pre id='MhAlm'><center id='MhAlm'></center></pre></bdo></b><th id='MhAlm'></th></span></q></dt></tr></i><div id='MhAlm'><tfoot id='MhAlm'></tfoot><dl id='MhAlm'><fieldset id='MhAlm'></fieldset></dl></div>
      • <bdo id='MhAlm'></bdo><ul id='MhAlm'></ul>

      1. <small id='MhAlm'></small><noframes id='MhAlm'>

        获取包含在 NSString 中的文件的扩展名

        时间:2023-05-31

        <tfoot id='XMOfj'></tfoot><legend id='XMOfj'><style id='XMOfj'><dir id='XMOfj'><q id='XMOfj'></q></dir></style></legend>
            <bdo id='XMOfj'></bdo><ul id='XMOfj'></ul>

                <tbody id='XMOfj'></tbody>

                <i id='XMOfj'><tr id='XMOfj'><dt id='XMOfj'><q id='XMOfj'><span id='XMOfj'><b id='XMOfj'><form id='XMOfj'><ins id='XMOfj'></ins><ul id='XMOfj'></ul><sub id='XMOfj'></sub></form><legend id='XMOfj'></legend><bdo id='XMOfj'><pre id='XMOfj'><center id='XMOfj'></center></pre></bdo></b><th id='XMOfj'></th></span></q></dt></tr></i><div id='XMOfj'><tfoot id='XMOfj'></tfoot><dl id='XMOfj'><fieldset id='XMOfj'></fieldset></dl></div>

                <small id='XMOfj'></small><noframes id='XMOfj'>

                • 本文介绍了获取包含在 NSString 中的文件的扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我有一个 NSMutable 字典,其中包含文件 ID 及其文件名+扩展名,格式为 fileone.doc 或 filetwo.pdf.我需要确定在我的 UITableView 中正确显示相关图标的文件类型.这是我到目前为止所做的.

                  I have an NSMutable dictionary that contains file IDs and their filename+extension in the simple form of fileone.doc or filetwo.pdf. I need to determine what type of file it is to correctly display a related icon in my UITableView. Here is what I have done so far.

                  NSString *docInfo = [NSString stringWithFormat:@"%d", indexPath.row]; //Determine what cell we are formatting
                  NSString *fileType = [contentFiles objectForKey:docInfo]; //Store the file name in a string
                  

                  我编写了两个正则表达式来确定我正在查看的文件类型,但它们从未返回肯定的结果.我之前没有在 iOS 编程中使用过正则表达式,所以我不完全确定我是否做得对,但我基本上是从 Class Description 页面复制了代码.

                  I wrote two regex to determine what type of file I'm looking at, but they never return a positive result. I haven't used regex in iOS programming before, so I'm not entirely sure if I'm doing it right, but I basically copied the code from the Class Description page.

                      NSError *error = NULL;
                  NSRegularExpression *regexPDF = [NSRegularExpression regularExpressionWithPattern:@"/^.*\.pdf$/" options:NSRegularExpressionCaseInsensitive error:&error];
                  NSRegularExpression *regexDOC = [NSRegularExpression regularExpressionWithPattern:@"/^.*\.(doc|docx)$/" options:NSRegularExpressionCaseInsensitive error:&error];
                      NSUInteger numMatch = [regexPDF numberOfMatchesInString:fileType options:0 range:NSMakeRange(0, [fileType length])];
                      NSLog(@"How many matches were found? %@", numMatch);
                  

                  我的问题是,有没有更简单的方法来做到这一点?如果不是,我的正则表达式不正确吗?最后,如果我必须使用它,运行时间成本高吗?我不知道用户平均拥有多少文件.

                  My questions would be, is there an easier way to do this? If not, are my regex incorrect? And finally if I have to use this, is it costly in run time? I don't know what the average amount of files a user will have will be.

                  谢谢.

                  推荐答案

                  你在找[fileType pathExtension]

                  NSString 文档:pathExtension

                  这篇关于获取包含在 NSString 中的文件的扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:iOS 5 SDK 中的容器视图是什么? 下一篇:在 iOS 5 上使用 Segues/Storyboard 弹出当前视图

                  相关文章

                  最新文章

                      <bdo id='LQRlk'></bdo><ul id='LQRlk'></ul>
                    <legend id='LQRlk'><style id='LQRlk'><dir id='LQRlk'><q id='LQRlk'></q></dir></style></legend>

                      <small id='LQRlk'></small><noframes id='LQRlk'>

                    1. <tfoot id='LQRlk'></tfoot>
                      <i id='LQRlk'><tr id='LQRlk'><dt id='LQRlk'><q id='LQRlk'><span id='LQRlk'><b id='LQRlk'><form id='LQRlk'><ins id='LQRlk'></ins><ul id='LQRlk'></ul><sub id='LQRlk'></sub></form><legend id='LQRlk'></legend><bdo id='LQRlk'><pre id='LQRlk'><center id='LQRlk'></center></pre></bdo></b><th id='LQRlk'></th></span></q></dt></tr></i><div id='LQRlk'><tfoot id='LQRlk'></tfoot><dl id='LQRlk'><fieldset id='LQRlk'></fieldset></dl></div>