"함수 get extension()"의 두 판 사이의 차이

27번째 줄: 27번째 줄:
<syntaxhighlight lang='csharp' run>
<syntaxhighlight lang='csharp' run>
using System;
using System;
using System.IO;
using static System.IO.File;
using static System.IO.File;
class Program {
class Program {

2021년 11월 2일 (화) 13:01 판

1 개요

get file extension()
get extension()
GetExtension()
  • 파일명에서 확장자 추출하는 함수
  • 예: "C:\mydir.old\myfile.ext" → "ext" 또는 ".ext"

2 Bash

filename='/home/run.sh'
extension="${filename##*.}"
echo $extension

3 C++

String^ fileName = "C:\\mydir.old\\myfile.ext";
String^ extension = Path::GetExtension( fileName ); // '.ext'

4 C#

using System;
using System.IO;
using static System.IO.File;
class Program {
    static void Main() {
        string fileName = @"C:\mydir.old\myfile.ext";
        string extension = Path.GetExtension(fileName);
        Console.WriteLine( extension );
    }
}

5 PHP

$extension = pathinfo($filename, PATHINFO_EXTENSION);
$path_parts = pathinfo($filename);
$extension = $path_parts['extension'];
$extension = substr( strrchr($filename, "."), 1 );
$extension = array_pop( explode('.', $filename) );

6 VB

Dim fileName As String = "C:\mydir.old\myfile.ext"
Dim extension As String
extension = Path.GetExtension(fileName)

7 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}