Rylah's Study & Daily Life

[C#/Study] 01. String 본문

Study/C#

[C#/Study] 01. String

Rylah 2022. 2. 26. 18:00
함수 설명 예제 결과
Contain 문자열 안에 해당하는 문자열이 있는지 확인 strSample.Contains("Test").ToString(); True
Equals 문자열이 해당 문자열과 동일한지 확인 strSample.Equals("Test").ToString(); False
Length 개체의 문자 수(길이)를 반환 strSample.Length.ToString(); 18
Replace 지정된 문자열을 다른 문자열로 모두 변환 strSampleReplace("Test", "I Can"); Sample, I Can, Test
Split 문자열을 조건에 맞는 문자열을 기준으로 분할 strSample.Split(","); Sample
Test
Text
Substring 문자열 내의 조건 위치의 부분 문자열을 검색 strSample.Substring(3, 5); mple,
ToLower 문자열을 소문자로 변환 strSample.ToLower(); sample, test, text
ToUpper 문자열을 대문자로 변환 strSample.ToUpper(); SAMPLE, TEST, TEXT
Trim 문자열 전, 후의 공백을 제거 strSample.Trim(); 공백 사라짐

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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_01_string
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void runButton_Click(object sender, EventArgs e)
        {
            //Sample, Test, Text
            string strText = lblText.Text;
 
 
            lblContain.Text = strText.Contains("Text").ToString();
            lblEqual.Text = strText.Equals("Text").ToString();
            lblLength.Text = strText.Length.ToString();
            lblReplace.Text = strText.Replace("Test""I Can").ToString();
 
            string[] strSplit = strText.Split(',');
            lblSplit_a.Text = strSplit[0].ToString();
            lblSplit_b.Text = strSplit[1].ToString();
            lblSplit_c.Text = strSplit[2].ToString().TrimStart();
 
            lblSubstring.Text = strText.Substring(35).ToString();
            lblToLower.Text = strText.ToLower().ToString();
            lblToUpper.Text = strText.ToUpper().ToString();
            lblTrim.Text = strText.Trim().ToString();
 
        }
    }
}
 
cs

Study_01_string.zip
0.04MB

 

https://cwkcw.tistory.com/59 

 

Doridori C# 강의) 1.string

====================================================== 안녕하세요 Doridori 입니다. C# 기초 강의를 만들어 볼까 합니다. 기본적으로 책으로 공부하거나 요약되어 있는 이론집같은 것만 보게 될경우 실제로 적..

cwkcw.tistory.com

 

https://youtu.be/boUIc2Y4cZo 

 

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

[C#/Study] 05. Enum  (0) 2022.02.27
[C#/Study] 04. Operator  (0) 2022.02.27
[C#/Study] 03. Method  (0) 2022.02.27
[C#/Study] 02. DataType / Overflow  (0) 2022.02.26
[C#/Study]00. Intro  (0) 2022.02.26