728x90

지정된 형식에 따라 개체의 값을 문자열로 변환하여 다른 문자열에 삽입한다.

string.Format("{0};{1};{2};{3};{4};{5}",textBox1.Text.Trim(), textBox2.Text.Trim(), textBox3.Text.Trim(), textBox4.Text.Trim(), textBox5.Text.Trim(), textBox6.Text.Trim());


숫자형식 포맷팅을 이용하면 숫자로 이루어진 문자열을 다양한 형태로 출력 할 수 있다.

기본적으로 이 포맷팅은 System. String.Format 매서드에 기반하여 적용된다.


형식지정자

종류

예제코드

출력결과

C / c

통화
Currency

 Response.Write(string.Format("{0:C}", 2.5));

₩3

 Response.Write(string.Format("{0:C}", -3.5));

-₩4

D / d

10진법
Decimal

 Response.Write(string.Format("{0:D}", 00035));

35

E / e

과학적지수
Scientific

 Response.Write(string.Format("{0:E}", 342));

3.420000E+02

F / f

고정 소수점
Fixed-point

 Response.Write(string.Format("{0:F2}", 35.22));

35.22

 Response.Write(string.Format("{0:F0}", 35.22));

35

G / g

일반
General

 Response.Write(string.Format("{0:G}", 123456));

123456

N / n

숫자
Number

 Response.Write(string.Format("{0:N}", 25000000));

25,000,000.00

P / p

백분율
Percentage

 Response.Write(string.Format("{0:P}", .21548));

21.55%

 Response.Write(string.Format("{0:P1}", .112345));

11.2%

X / x

16진법
Hexadecimal

 Response.Write(string.Format("{0:X}", 250));

FA

 Response.Write(string.Format("{0:X}", 0xffff));

FFFF


출처 : http://www.dreamy.pe.kr/zbxe/CodeClip/157656


http://ryuschool.tistory.com/entry/C-%EB%AC%B8%EC%9E%90%EC%97%B4-StringFormat


이곳에 가면 String.Format 에 대한 샘플이 있으니 참고하면 된다.

http://www.csharp-examples.net/string-format-double/


블로그 이미지

Link2Me

,