트림
문자열에서 모든 선행 및 후행 공백을 제거하는 문자열 메서드입니다.
예를 들어, 문자열 "jack sparrow" trim()을 사용하여 선행 및 공백 없이 다음과 같이 반환됩니다.
jack sparrow
다음은 예입니다 -
예시
using System;
namespace Demo {
class Program {
static void Main(string[] args) {
string str = " Amit ";
Console.WriteLine(str);
// trim
Console.WriteLine("After removing leading and trailing whitespace...");
string res = str.Trim();
Console.WriteLine(res);
Console.ReadKey();
}
}
} 출력
Amit After removing leading and trailing whitespace... Amit
트림 시작()
TrimStart() 메서드는 배열에 지정된 문자 집합의 선행 항목을 모두 제거합니다.
모든 선행 0을 제거하는 예를 살펴보겠습니다. −
using System;
class Program {
static void Main() {
String str ="0009678".TrimStart(new Char[] { '0' } );
Console.WriteLine(str);
}
} 출력
9678