Coding/C#
c# 프로그래밍 무조건 따라하기 _string편
찡콩찡
2022. 12. 22. 10:53
https://www.youtube.com/watch?v=boUIc2Y4cZo&list=PLoFFz2j8yxxxH_3ustbHATXtMsHZ-Saei
String에 있는 개념
함수 | 설명 |
Contain | 문자열 안에 해당 하는 문자열이 있는지 확인 (true / false로 값을 반환) |
Equals | 문자열이 해당 문자열과 동일 한지 확인 (true / false로 값을 반환) |
Length | 개체의 문자 수를 반환 |
Replace | 지정된 문자열을 다른 문자열로 모두 반환 |
Split | 문자열에서 조건에 맞는 문자를 기준으로 반환 |
Substring | 문자열 내의 조건 위치의 부분 문자열을 검색 |
ToLower | 문자열을 소문자로 변환 |
ToUpper | 문자열을 대문자로 변환 |
Trim | 문자열 전,후의 공백을 제거 |
Form1.cs 코드
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Study_string
{
public partial class a : Form
{
public a()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//Sample, Test, Text 실행버튼 눌렀을 시,
string strText = lblTest.Text;
lblContain.Text = strText.Contains("Text").ToString();
lblEquals.Text = strText.Equals("Test").ToString();
lblLength.Text = strText.Length.ToString();
lblReplace.Text = strText.Replace("Test", " love").ToString();
string[] strSplit = strText.Split(',');
lblSplit1.Text = strSplit[0].ToString();
lblSplit2.Text = strSplit[1].ToString();
lblSplit3.Text = strSplit[2].ToString();
lblSubstring.Text = strText.Substring(3, 5).ToString();
lblToLower.Text = strText.ToLower().ToString();
lblToUpper.Text = strText.ToUpper().ToString();
lblTrim.Text = strText.Trim().ToString();
}
}
}
만든 UI
실행결과