Path.GetExtension メソッド
定義
オーバーロード
GetExtension(String) |
指定のパス文字列の拡張子 (ピリオド "." を含む) を返します。Returns the extension (including the period ".") of the specified path string. |
GetExtension(ReadOnlySpan<Char>) |
読み取り専用の文字範囲で表されたファイル パスの拡張子を返します。Returns the extension of a file path that is represented by a read-only character span. |
GetExtension(String)
指定のパス文字列の拡張子 (ピリオド "." を含む) を返します。Returns the extension (including the period ".") of the specified path string.
public:
static System::String ^ GetExtension(System::String ^ path);
public static string GetExtension (string path);
static member GetExtension : string -> string
Public Shared Function GetExtension (path As String) As String
パラメーター
- path
- String
拡張子の取得元のパス文字列。The path string from which to get the extension.
戻り値
指定したパスの拡張子 (ピリオド "." を含む)、null
、または Empty。The extension of the specified path (including the period "."), or null
, or Empty. path
が null
の場合、GetExtension(String) は null
を返します。If path
is null
, GetExtension(String) returns null
. path
が拡張子情報を持たない場合、GetExtension(String) は Empty を返します。If path
does not have extension information, GetExtension(String) returns Empty.
例外
path
が、GetInvalidPathChars() で定義されている無効な文字を 1 つ以上含んでいます。path
contains one or more of the invalid characters defined in GetInvalidPathChars().
例
次の例は、Windows ベースのデスクトッププラットフォームで GetExtension
メソッドを使用する方法を示しています。The following example demonstrates using the GetExtension
method on a Windows-based desktop platform.
String^ fileName = "C:\\mydir.old\\myfile.ext";
String^ path = "C:\\mydir.old\\";
String^ extension;
extension = Path::GetExtension( fileName );
Console::WriteLine( "GetExtension('{0}') returns '{1}'", fileName, extension );
extension = Path::GetExtension( path );
Console::WriteLine( "GetExtension('{0}') returns '{1}'", path, extension );
// This code produces output similar to the following:
//
// GetExtension('C:\mydir.old\myfile.ext') returns '.ext'
// GetExtension('C:\mydir.old\') returns ''
string fileName = @"C:\mydir.old\myfile.ext";
string path = @"C:\mydir.old\";
string extension;
extension = Path.GetExtension(fileName);
Console.WriteLine("GetExtension('{0}') returns '{1}'",
fileName, extension);
extension = Path.GetExtension(path);
Console.WriteLine("GetExtension('{0}') returns '{1}'",
path, extension);
// This code produces output similar to the following:
//
// GetExtension('C:\mydir.old\myfile.ext') returns '.ext'
// GetExtension('C:\mydir.old\') returns ''
Dim fileName As String = "C:\mydir.old\myfile.ext"
Dim pathname As String = "C:\mydir.old\"
Dim extension As String
extension = Path.GetExtension(fileName)
Console.WriteLine("GetExtension('{0}') returns '{1}'", fileName, extension)
extension = Path.GetExtension(pathname)
Console.WriteLine("GetExtension('{0}') returns '{1}'", pathname, extension)
' This code produces output similar to the following:
'
' GetExtension('C:\mydir.old\myfile.ext') returns '.ext'
' GetExtension('C:\mydir.old\') returns ''
注釈
このメソッドは path
の拡張を取得します。そのためには、ピリオド (.) に対して path
を検索し、path
の最後の文字から始まり、最初の文字に進みます。This method obtains the extension of path
by searching path
for a period (.), starting with the last character in path
and continuing toward the first character. @No__t-0 または AltDirectorySeparatorChar 文字の前にピリオドがある場合、返される文字列にはピリオドとその後の文字が含まれます。それ以外の場合は、String.Empty が返されます。If a period is found before a DirectorySeparatorChar or AltDirectorySeparatorChar character, the returned string contains the period and the characters after it; otherwise, String.Empty is returned.
共通 I/O タスクの一覧は、 共通 I/O タスク を参照してください。For a list of common I/O tasks, see Common I/O Tasks.
こちらもご覧ください
GetExtension(ReadOnlySpan<Char>)
読み取り専用の文字範囲で表されたファイル パスの拡張子を返します。Returns the extension of a file path that is represented by a read-only character span.
public:
static ReadOnlySpan<char> GetExtension(ReadOnlySpan<char> path);
public static ReadOnlySpan<char> GetExtension (ReadOnlySpan<char> path);
static member GetExtension : ReadOnlySpan<char> -> ReadOnlySpan<char>
Public Shared Function GetExtension (path As ReadOnlySpan(Of Char)) As ReadOnlySpan(Of Char)
パラメーター
- path
- ReadOnlySpan<Char>
拡張子の取得元のファイル パス。The file path from which to get the extension.
戻り値
指定されたパスの拡張子 (ピリオド "." を含む)。path
に拡張子情報が含まれていない場合は Empty。The extension of the specified path (including the period, "."), or Empty if path
does not have extension information.
注釈
このメソッドは path
の拡張を取得します。これは、ピリオド (".") に対して path
を検索することによって、読み取り専用スパンの最後の文字から始まり、その最初の文字に向かって続行します。This method obtains the extension of path
by searching path
for a period ("."), starting from the last character in the read-only span and continuing toward its first character. @No__t-0 または AltDirectorySeparatorChar 文字の前にピリオドがある場合、返される読み取り専用スパンにはピリオドとその後の文字が含まれます。それ以外の場合は、ReadOnlySpan<T>.Empty が返されます。If a period is found before a DirectorySeparatorChar or AltDirectorySeparatorChar character, the returned read-only span contains the period and the characters after it; otherwise, ReadOnlySpan<T>.Empty is returned.