繁体   English   中英

如何从文件名中提取Guid?

[英]How to extract Guid from file name?

我想从下面的字符串数组中提取 Guid 并希望输出如下:

Output:Log.txt,Logging.txt

string[] str = new string[] { "1250a2d5-cd40-4bcc-a979-9d6f2cd62b9fLog.txt", "bdb31966-e3c4-4344-b02c-305c0eb0fa0aLogging.txt" }; //file name are Log.txt and Logging.txt
List<string> list= new List<string>();
foreach (var item in str)
{
    if (!string.IsNullOrEmpty(item))
    {
        list.Add();  // here i want to store Log.txt and Logging.txt
    }
}

这该怎么做??

var str = new string[] { "1250a2d5-cd40-4bcc-a979-9d6f2cd62b9fLog.txt", "bdb31966-e3c4-4344-b02c-305c0eb0fa0aLogging.txt" }; //file name are Log.txt and Logging.txt

var arr = str.Select(s=>s.Substring(36)).Where(s=>s.Any()).ToArray();

你可以在这里看到它的实际效果: https : //dotnetfiddle.net/eHy6Fo

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM