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. または文字の前にピリオドがある場合 DirectorySeparatorChar 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.
こちらもご覧ください
- Windows システムのファイル パス形式File path formats on Windows systems
- ファイルおよびストリーム入出力File and Stream I/O
- 方法:ファイルからのテキストの読み取りHow to: Read Text from a File
- 方法:ファイルにテキストを書き込むHow to: Write Text to a File
適用対象
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. または文字の前にピリオドがある場合 DirectorySeparatorChar 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.