本文整理匯總了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();
}