Path.GetExtension Path.GetExtension Path.GetExtension Path.GetExtension Method

定義

オーバーロード

GetExtension(String) GetExtension(String) GetExtension(String) GetExtension(String)

指定のパス文字列の拡張子 (ピリオド "." を含む) を返します。Returns the extension (including the period ".") of the specified path string.

GetExtension(ReadOnlySpan<Char>) GetExtension(ReadOnlySpan<Char>) GetExtension(ReadOnlySpan<Char>) GetExtension(ReadOnlySpan<Char>)

読み取り専用の文字範囲で表されたファイル パスの拡張子を返します。Returns the extension of a file path that is represented by a read-only character span.

GetExtension(String) GetExtension(String) GetExtension(String) 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 String String String

拡張子の取得元のパス文字列。The path string from which to get the extension.

戻り値

指定したパスの拡張子 (ピリオド "." を含む)、null、または EmptyThe extension of the specified path (including the period "."), or null, or Empty. pathnull の場合、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().

次の例を使用して、 GetExtension Windows ベースのデスクトップ プラットフォーム上のメソッド。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.

こちらもご覧ください

GetExtension(ReadOnlySpan<Char>) GetExtension(ReadOnlySpan<Char>) GetExtension(ReadOnlySpan<Char>) 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 に拡張子情報が含まれていない場合は EmptyThe 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.

こちらもご覧ください

適用対象