本文整理汇总了C#中java.lang.String.lastIndexOf方法的典型用法代码示例。如果您正苦于以下问题:C# String.lastIndexOf方法的具体用法?C# String.lastIndexOf怎么用?C# String.lastIndexOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.String
的用法示例。
在下文中一共展示了String.lastIndexOf方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getDirectoryName
public static String getDirectoryName(String path) {
if (path != null) {
int index = path.lastIndexOf(DIRECTORY_SEPARATOR_CHAR);
int index2 = path.lastIndexOf(ALT_DIRECTORY_SEPARATOR_CHAR);
if (index2 > index) {
index = index2;
}
if (index != -1) {
if (index == path.length() - 1) {
if (path.indexOf(VOLUME_SEPARATOR_CHAR) == index - 1) {
return null;
} else {
path = path.substring(0, index);
}
} else {
if (path.indexOf(VOLUME_SEPARATOR_CHAR) == index - 1) {
path = path.substring(0, index + 1);
} else {
path = path.substring(0, index);
}
}
if (path.length() == 2 && path[1] == VOLUME_SEPARATOR_CHAR) {
return "";
}
}
return path;
}
return null;
}
示例2: getFileName
public static String getFileName(String path) {
if (path != null) {
int index = path.lastIndexOf(DIRECTORY_SEPARATOR_CHAR);
if (index == -1) {
index = path.lastIndexOf(ALT_DIRECTORY_SEPARATOR_CHAR);
}
if (index == -1) {
return path;
}
return path.substring(index + 1);
}
return null;
}
示例3: getFileNameWithoutExtension
public static String getFileNameWithoutExtension(String path) {
if (path != null) {
int index = path.lastIndexOf(DIRECTORY_SEPARATOR_CHAR);
if (index == -1) {
index = path.lastIndexOf(ALT_DIRECTORY_SEPARATOR_CHAR);
}
if (index != -1) {
path = path.substring(index + 1);
}
index = path.lastIndexOf('.');
if (index == -1) {
return path;
}
return path.substring(0, index);
}
return null;
}
示例4: getExtension
public static String getExtension(String path) {
if (path != null) {
int index = path.lastIndexOf('.');
if (index == -1) {
return "";
}
return path.substring(index);
}
return null;
}
示例5: hasExtension
public static bool hasExtension(String path) {
int index = path.lastIndexOf('.');
if (index == -1) {
return false;
}
return (index + 1) != path.length();
}