C#

문자 앞뒤로 특정 문자 입력 (RightPad, LeftPad)

잼잼재미 2023. 11. 13. 15:07

 - string변수 앞뒤로 특정 문자를 입력하기 위해선 PadLeft, PadRight함수를 활용.

 

string str = "hello";
str = str.PadRight(10, '#'); // 총 글자수 : 10       
Console.WriteLine(str);
// 출력값  : hello#####

string str = "hello";
str = str.PadLeft(10, '#'); // 총 글자수 : 10      
Console.WriteLine(str);
// 출력값  : #####hello

'C#' 카테고리의 다른 글

범위 내 입력값 받기  (1) 2023.11.13
콘솔 글자색 변경  (0) 2023.11.13
열거형 (Enums)  (0) 2023.11.10
인터페이스(Interface)  (0) 2023.11.09
out, ref 키워드  (0) 2023.11.08