GVKun编程网logo

在C#中将我自己的非法字符插入Path.GetInvalidFileNameChars()(c#路径中有非法字符)

5

对于想了解在C#中将我自己的非法字符插入Path.GetInvalidFileNameChars()的读者,本文将是一篇不可错过的文章,我们将详细介绍c#路径中有非法字符,并且为您提供关于c#–新的F

对于想了解在C#中将我自己的非法字符插入Path.GetInvalidFileNameChars()的读者,本文将是一篇不可错过的文章,我们将详细介绍c#路径中有非法字符,并且为您提供关于c# – 新的FileInfo(路径).Name与Path.GetFileName(路径)、C# 的 Path.GetFileName、Path.GetExtension、Path.GetDirectoryName千一网络 http://www.itpow.com/、Check failed: DeviceNameUtils::ParseFullName(name(), &parsed_name_) Invalid device name: /job:/replica:0/task:0/cpu:0、com.intellij.openapi.fileTypes.WildcardFileNameMatcher的实例源码的有价值信息。

本文目录一览:

在C#中将我自己的非法字符插入Path.GetInvalidFileNameChars()(c#路径中有非法字符)

在C#中将我自己的非法字符插入Path.GetInvalidFileNameChars()(c#路径中有非法字符)

如何扩展Path.GetInvalidFileNameChars以包含我自己的应用程序中非法的字符集?

string invalid = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidpathChars());

如果我想添加’&’作为一个非法角色,我可以这样做吗?

解决方法

您无法修改现有函数,但可以编写一个返回Path.GetInvalidFileNameChars()和非法字符的包装函数.

public static string GetInvalidFileNameChars() {
    return Path.GetInvalidFileNameChars().Concat(MY_INVALID_FILENAME_CHARS);
}

c# – 新的FileInfo(路径).Name与Path.GetFileName(路径)

c# – 新的FileInfo(路径).Name与Path.GetFileName(路径)

哪一个更好的使用和为什么?
我的意思是这两个命令在哪些方面不同呢?
性能,可读性,…

新的FileInfo(path).Name或Path.GetFileName(path)

解决方法

只需要创建一个新的对象即可使用Path.GetFilename(),它将执行得更好.

以下是两者的比较:

码:

Path.GetFileName("G:\\u.png")

IL:

IL_0000:  ldstr       "G:\u.png"
IL_0005:  call        System.IO.Path.GetFileName

码:

new FileInfo("G:\\u.png").Name

IL:

IL_0000:  ldstr       "G:\u.png"
IL_0005:  newobj      System.IO.FileInfo..ctor
IL_000A:  callvirt    System.IO.FileSystemInfo.get_Name

C# 的 Path.GetFileName、Path.GetExtension、Path.GetDirectoryName千一网络 http://www.itpow.com/

C# 的 Path.GetFileName、Path.GetExtension、Path.GetDirectoryName千一网络 http://www.itpow.com/

http://www.itpow.com/ 千一网络

Path.GetFileName

string s1 = Path.GetFileName("D:\\dir\\asp.net\\readme.txt"); // readme.text
string s2 = Path.GetFileName("D:\\dir\\asp.net\\readme."); // readme.
string s3 = Path.GetFileName("D:\\dir\\asp.net\\readme"); // readme
string s4 = Path.GetFileName("D:\\dir\\asp.net\\readme\\"); // 零长度字符串
string s5 = Path.GetFileName("D:\\"); // 零长度字符串
string s6 = Path.GetFileName("D:"); // 零长度字符串

说明:路径中的 \ 和 / 是一样的结果。

只要不是以 \ 或 / 结束,都是当作文件对待(盘符除外)。

Path.GetExtension

string s1 = Path.GetExtension("D:\\dir\\asp.net\\readme.txt"); // .txt
string s2 = Path.GetExtension("D:\\dir\\asp.net\\readme."); // 零长度字符串
string s3 = Path.GetExtension("D:\\dir\\asp.net\\readme"); // 零长度字符串
string s4 = Path.GetExtension("D:\\dir\\asp.net\\readme\\"); // 零长度字符串
string s5 = Path.GetExtension("D:\\"); // 零长度字符串
string s6 = Path.GetExtension("D:"); // 零长度字符串

Path.GetDirectoryName

string s1 = Path.GetDirectoryName("D:\\dir\\asp.net/readme.txt"); // D:\dir\asp.net
string s2 = Path.GetDirectoryName("D:\\dir\\asp.net/readme."); // D:\dir\asp.net
string s3 = Path.GetDirectoryName("D:\\dir\\asp.net/readme"); // D:\dir\asp.net
string s4 = Path.GetDirectoryName("D:\\dir\\asp.net/readme/"); // D:\dir\asp.net\readme
string s5 = Path.GetDirectoryName("D:\\"); // null,注意是 null
string s6 = Path.GetDirectoryName("D:"); // null,注意是 null

这里,我们故意在路径中使用“/”,可以发现最终还是会转换成“\”。

原文连接:http://www.cftea.com/c/2017/02/6812.asp

Check failed: DeviceNameUtils::ParseFullName(name(), &parsed_name_) Invalid device name: /job:/replica:0/task:0/cpu:0

Check failed: DeviceNameUtils::ParseFullName(name(), &parsed_name_) Invalid device name: /job:/replica:0/task:0/cpu:0

D:\Users\Administrator\AppData\Local\Programs\Python\Python35\python.exe D:/360c/colajia-tensorflow-master/tensorflow/mnist/test.py
F c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\common_runtime\device.cc:29] Check failed: DeviceNameUtils::ParseFullName(name(), &parsed_name_) Invalid device name: /job:/replica:0/task:0/cpu:0

com.intellij.openapi.fileTypes.WildcardFileNameMatcher的实例源码

com.intellij.openapi.fileTypes.WildcardFileNameMatcher的实例源码

项目:intellij-ce-playground    文件:FileNameMatcherFactoryImpl.java   
@NotNull
public FileNameMatcher createMatcher(@NotNull String pattern) {
  if (pattern.startsWith("*.") &&
      pattern.indexOf('*',2) < 0 &&
      pattern.indexOf('.',2) < 0 &&
      pattern.indexOf('?',2) < 0) {
    return new ExtensionFileNameMatcher(pattern.substring(2).toLowerCase());
  }

  if (pattern.contains("*") || pattern.contains("?")) {
    return new WildcardFileNameMatcher(pattern);
  }

  return new ExactFileNameMatcher(pattern);
}
项目:tools-idea    文件:FileNameMatcherFactoryImpl.java   
@NotNull
public FileNameMatcher createMatcher(@NotNull String pattern) {
  if (pattern.startsWith("*.") &&
      pattern.indexOf('*',2) < 0) {
    return new ExtensionFileNameMatcher(pattern.substring(2).toLowerCase());
  }

  if (pattern.contains("*") || pattern.contains("?")) {
    return new WildcardFileNameMatcher(pattern);
  }

  return new ExactFileNameMatcher(pattern);
}
项目:GoJetPlugin    文件:JetFileTypeFactory.java   
@Override
public void createFileTypes(@NotNull FileTypeConsumer consumer) {
    consumer.consume(JetFileType.INSTANCE,"jet");
    consumer.consume(JetFileType.INSTANCE,new WildcardFileNameMatcher("*.jet.html"));
}

关于在C#中将我自己的非法字符插入Path.GetInvalidFileNameChars()c#路径中有非法字符的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于c# – 新的FileInfo(路径).Name与Path.GetFileName(路径)、C# 的 Path.GetFileName、Path.GetExtension、Path.GetDirectoryName千一网络 http://www.itpow.com/、Check failed: DeviceNameUtils::ParseFullName(name(), &parsed_name_) Invalid device name: /job:/replica:0/task:0/cpu:0、com.intellij.openapi.fileTypes.WildcardFileNameMatcher的实例源码等相关知识的信息别忘了在本站进行查找喔。

本文标签: