연습문제/C# 연습문제
1. 특정 문자 또는 문자열 제거
규남
2023. 7. 23. 19:26
반응형
<코드 입력>
namespace Test
{
internal class Program
{
static void Main(string[] args)
{
// 원본
string str = "abcdef";
Console.WriteLine(str);
// 제거할 문자 내용
string tmp1 = "abc";
string tmp2 = "f";
// abcdef 문자열에서 abc 문자열을 제거
// Replace : 문자열 치환
string result = str.Replace(tmp1, "");
Console.WriteLine(result);
result = str.Replace(tmp2, "");
Console.WriteLine(result);
// ef를 aaaaaa로 변경
result = str.Replace("ef", "aaaaaa");
Console.WriteLine(result);
}
}
}
<결과 확인>
728x90
반응형