본문 바로가기
프로그래밍

이스케이프 문자(Escape Character)에 대해서

by bantomak 2025. 2. 12.
반응형

이스케이프 문자

이스케이프 문자(escape character)는 특수한 기능을 수행하는 문자로, 화면에 출력되는 문자가 아니라 문자 출력을 제어하는 문자이다. 대부분의 프로그래밍 언어나 셸에서는 백슬래시(\) 또는 퍼센트 기호(%), 달러 기호($) 등을 이용해 이스케이프 시퀀스를 표현한다.

📌주요 이스케이프 문자 정리

  • \n : 줄바꿈(Line Feed)
  • \r : 캐리지 리턴(Carrage Return)
  • \b : 백스페이스(Backspace)
  • \t : 탭(Tab)
  • \v : 수직 탭(Vertical Tab)
  • \f : 폼 피드(Form Feed)
  • \\ : 백슬래시(\) 자체
  • \' : 작은 따옴표(Single Quote)
  • \" : 큰 따옴표(Double Quote)

줄 바꿈 문자 Line Feed(LF) : \n

static void Main()
{
    Console.WriteLine("hello, \nworld.");
}

캐리지 리턴 문자 Carriage Return(CR) : \r

static void Main()
{
    Console.WriteLine("hello, \rworld.");
}

백스페이스 Backspace : \b

static void Main()
{
    Console.WriteLine("hello, \bworld.");
}

탭 문자 Tab : \t

static void Main()
{
    Console.WriteLine("hello, \tworld.");
}

수직 탭 Vertical Tab : \v

static void Main()
{
    Console.WriteLine("hello, \vworld.");
}

echo -e "hello, \vworld"

bash 환경에서 실행

폼 피드 Form Feed : \f

static void Main()
{
    Console.WriteLine("hello, \fworld.");
}

echo -e "hello, \fworld"

bash 환경에서 실행

백슬래시 Backslash : \\

static void Main()
{
    Console.WriteLine("hello, \\world.");
}

작은 따옴표 Single Quote : \'

static void Main()
{
    Console.WriteLine("hello, \'world.");
}

큰 따옴표 Double Quote : \"

static void Main()
{
    Console.WriteLine("hello, \"world.");
}

정리하자면

이스케이프 문자는 특수 문자를 사용하거나 제어 기능을 수행할 때 필수적이다.

자주 사용되는 이스케이프 문자는 이름과 사용방법에 대해서 꼭 숙지해 두도록 하자.

함께 읽으면 좋은 글

 

줄 끝 스타일(Line Ending Style) - 윈도우 스타일 vs 리눅스 스타일

줄 끝 스타일(Line Ending Style)줄 끝(라인 엔딩, Line Ending) 스타일은 운영체제(OS)에 따라 다르게 처리될 수 있다. 이에 대해서 알아보자.1. 윈도우 스타일 / 도스(DOS) 스타일 (CRLF, \r\n)CRLF는 Carriage Return

jettstream.tistory.com

댓글