2015년 10월 15일 목요일

C# 개행문자 및 축약(@),정규문자열 예제

//C# 개행문자 및 축약,정규문자열 예제
using System;
using System.Data;
using System.Data.OleDb;
class Sample
{
    public static void Main()
    {
        //이스케이프 문자 예제, \t:TAB, \r\n:개행문자열
        string names = "이름 :  1\t김길동 2\t나길동 3";          
        string addrs = "주소 1\r\n서울 2\r\nRow부산";

        //verbatim string literal.(축약 문자)
        string filePath1 = @"C:\Users\Documents\";
        //string filePath2 = "C:\Users\Documents\";  //에러, 경로구분자 "\"는 @없이 하나만 사용 불가

        //regular string literal.(정규 문자 표현식)
        string filePath2 = "C:\\Users\\Documents\\";  

        Console.WriteLine("names : {0}" , names);
        Console.WriteLine("addrs : {0}" , addrs);
        Console.WriteLine("filePath1 : {0}" , filePath1);
        Console.WriteLine("filePath2 : {0}" , filePath2);

    }
}

[결과]

names : 이름 :  1       김길동 2        나길동 3
addrs : 주소 1
서울 2
Row부산
filePath1 : C:\Users\Documents\
filePath2 : C:\Users\Documents\

댓글 없음:

댓글 쓰기