250x250
Rainbow๐ŸŒˆCoder
My dev Note๐Ÿ“’
Rainbow๐ŸŒˆCoder
์ „์ฒด ๋ฐฉ๋ฌธ์ž
์˜ค๋Š˜
์–ด์ œ
  • ๋ถ„๋ฅ˜ ์ „์ฒด๋ณด๊ธฐ (411)
    • ๊ณต์ง€์‚ฌํ•ญ (0)
    • Debugger (10)
      • Visual Studio Debugger (1)
      • Chrome DevTools (3)
      • Visual Studio Code Debugger (4)
      • eclipse (1)
      • intelliJ (1)
    • OOP (2)
      • OOP (2)
    • TypeScript (54)
      • ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ TypeScript (54)
    • Javascript (87)
      • Javascript (45)
      • Node.js (19)
      • React (5)
      • FE ๊ฐœ๋ฐœํ™˜๊ฒฝ์„ค์ • (3)
      • React์™€ Node ๊ฐ™์ด ๋•Œ๋ ค์žก๊ธฐ (6)
      • next.js (2)
      • pixi.js (7)
    • ๋งˆํฌ์—… (23)
      • Html & Css (23)
    • C# (80)
      • C# (12)
      • ์ด๊ฒƒ์ด C#์ด๋‹ค (68)
    • C++ (30)
      • c++ (27)
      • win api (3)
    • Unity (18)
      • Unity(๊ธฐ์ดˆ) (8)
      • Unity(C#์ค‘๊ธ‰) (5)
      • ์œ ๋‹ˆํ‹ฐ ํฌํ†ค(๋„คํŠธ์›Œํฌ) (4)
      • unity c# MyCode (1)
    • Java & Spring (29)
      • Java (11)
      • ์Šคํ”„๋ง (8)
      • Java Algorithm (9)
      • Javs Data Structures (1)
    • ์ž๋ฃŒ๊ตฌ์กฐ์™€ ์•Œ๊ณ ๋ฆฌ์ฆ˜ (15)
      • ์ž๋ฃŒ๊ตฌ์กฐ (5)
      • ์•Œ๊ณ ๋ฆฌ์ฆ˜ (10)
    • ํ˜•์ƒ๊ด€๋ฆฌ (15)
      • Git (11)
      • ์†Œ์ŠคํŠธ๋ฆฌ (3)
    • ๊ทธ๋ž˜ํ”ฝ์Šค (7)
      • WebGl (7)
    • AWS (3)
      • aws (3)
    • ๋ฆฌ๋ˆ…์Šค (5)
      • ๋ฆฌ๋ˆ…์Šค (5)
    • ์ฑ… ๋ฆฌ๋ทฐ (13)
      • ํด๋ฆฐ์ฝ”๋“œ(์ฑ…๋ฆฌ๋ทฐ) (3)
      • ์œ ์ง€๋ณด์ˆ˜๊ฐ€๋Šฅํ•œ์ฝ”๋”ฉ์˜๊ธฐ์ˆ C#ํŽธ(์ฑ…๋ฆฌ๋ทฐ) (1)
      • ๋ฆฌํŒฉํ† ๋ง(์ž๋ฐ”์Šคํฌ๋ฆฝํŠธํŒ) (9)
    • Server (2)
      • ๊ฒŒ์ž„ ์„œ๋ฒ„(๋„คํŠธ์›Œํฌ, ๋ฉ€ํ‹ฐ์“ฐ๋ ˆ๋“œ,OS) (2)
    • ์„ค๊ณ„, ์•„ํ‚คํ…์ณ (4)
    • ํŒŒ์ด์ฌ (5)
    • ๋””์ž์ธํŒจํ„ด (2)
    • mocha (2)
    • Jest (1)
    • Spine (1)
    • ์ธ๊ณต์ง€๋Šฅ (1)
      • ํ˜ผ์ž๊ณต๋ถ€ํ•˜๋Š”๋จธ์‹ ๋Ÿฌ๋‹+๋”ฅ๋Ÿฌ๋‹ (1)

๋ธ”๋กœ๊ทธ ๋ฉ”๋‰ด

  • ํ™ˆ
  • ํƒœ๊ทธ
  • ๋ฐฉ๋ช…๋ก

๊ณต์ง€์‚ฌํ•ญ

์ธ๊ธฐ ๊ธ€

ํƒœ๊ทธ

  • ์ปดํฌ์ง€์…˜
  • MySQL
  • ใ…ฃใ„ท
  • ์œ„์ž„

์ตœ๊ทผ ๋Œ“๊ธ€

์ตœ๊ทผ ๊ธ€

ํ‹ฐ์Šคํ† ๋ฆฌ

hELLO ยท Designed By ์ •์ƒ์šฐ.
Rainbow๐ŸŒˆCoder

My dev Note๐Ÿ“’

10. ๋ฌธ์ž์—ด ๋‹ค๋ฃจ๊ธฐ
C#/์ด๊ฒƒ์ด C#์ด๋‹ค

10. ๋ฌธ์ž์—ด ๋‹ค๋ฃจ๊ธฐ

2022. 2. 7. 18:32
728x90

string ํ˜•์‹์€ ๊ทธ์ € ๋ฌธ์ž์—ด์„ ๋‹ด๋Š” ์—ญํ• ์„ ํ•  ๋ฟ ์•„๋‹ˆ๋ผ,

๋ฌธ์ž์—ด์„ ๊ฐ€๊ณตํ•˜๊ธฐ ์œ„ํ•œ ๋‹ค์–‘ํ•œ ๊ธฐ๋Šฅ๋„ ํ•จ๊ป˜ ์ œ๊ณตํ•œ๋‹ค.

 

<๋ชฉ์ฐจ>

(1) ๋ฌธ์ž์—ด ์•ˆ์—์„œ ์ฐพ๊ธฐ : ๋ฌธ์ž์—ด ๋‚ด์˜ ์–ด๋А ๋ถ€๋ถ„์„ ๊ฐ€๊ณตํ•  ๊ฒƒ์ธ๊ฐ€

(2) ๋ฌธ์ž์—ด ๋ณ€ํ˜•ํ•˜๊ธฐ : ๋ฌธ์ž์—ด ์ค‘๊ฐ„์— ์‚ฝ์ž…, ์‚ญ์ œ, ๋Œ€์†Œ๋ฌธ์ž ๋ณ€ํ™˜, ๋ฌธ์ž์—ด ์•ž/๋’ค ๊ณต๋ฐฑ์ œ๊ฑฐ(๊ณต๋ฐฑ์ œ๊ฑฐ ๋ฉ”์†Œ๋“œ ์ค‘์š”!)

(3) ๋ฌธ์ž์—ด ๋ถ„ํ• ํ•˜๊ธฐ : ๋ฌธ์ž์—ด ์ž๋ฅด๊ธฐ, ๋ฌธ์ž์—ด ๋ถ„๋ฆฌํ•˜๊ธฐ

(4) ๋ฌธ์ž์—ด ์„œ์‹๋งž์ถ”๊ธฐ : ๋ฌธ์ž์—ด์ด ์ผ์ •ํ•œ ํ‹€๊ณผ ๋ชจ์–‘์„ ๊ฐ–์ถ”๋„๋ก ๋งŒ๋“ค๊ธฐ

(5) ์™ผ์ชฝ/ ์˜ค๋ฅธ์ชฝ ๋งž์ถค

(6) ์ˆซ์ž ์„œ์‹ํ™”

(7) ๋‚ ์งœ ๋ฐ ์‹œ๊ฐ„ ์„œ์‹ํ™”

(8) ๋ฌธ์ž์—ด ๋ณด๊ฐ„

 

 

 

 

(1) ๋ฌธ์ž์—ด ์•ˆ์—์„œ ์ฐพ๊ธฐ

๋ฉ”์†Œ๋“œ ์„ค๋ช…
IndexOf() ํŠน์ • ๋ฌธ์ž์—ด์˜ ์œ„์น˜๋ฅผ ์ฐพ๋Š”๋‹ค.
LastIndexOf() ํŠน์ • ๋ฌธ์ž์—ด์˜ ์œ„์น˜๋ฅผ ๋’ค์—์„œ๋ถ€ํ„ฐ ์ฐพ๋Š”๋‹ค.
StartsWith() ํ˜„์žฌ ๋ฌธ์ž์—ด์ด ํŠน์ • ๋ฌธ์ž์—ด๋กœ ์‹œ์ž‘ํ•˜๋Š”์ง€๋ฅผ ํ‰๊ฐ€ํ•œ๋‹ค.
EndsWith() ํ˜„์žฌ ๋ฌธ์ž์—ด์ด ํŠน์ • ๋ฌธ์ž์—ด๋กœ ๋๋‚˜๋Š”์ง€๋ฅผ ํ‰๊ฐ€ํ•œ๋‹ค.
Contains() ํŠน์ • ๋ฌธ์ž์—ด์„ ํฌํ•จํ•˜๋Š”์ง€ ํ‰๊ฐ€ํ•œ๋‹ค.
Replace() ํŠน์ • ๋ฌธ์ž์—ด์ด ๋‹ค๋ฅธ ์ง€์ •๋œ ๋ฌธ์ž์—ด๋กœ ๋ชจ๋‘ ๋ฐ”๋€ ์ƒˆ ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
using System;
using System.Text;
using static System.Console;

namespace Hello
{
    class MainApp
    {
        static void Main(string[] args)
        {
            string greeting = "Good Morning";

            //IndexOf()
            WriteLine($"IndexOf 'Good' : {greeting.IndexOf("Good")}"); //IndexOf 'Good' : 0
            WriteLine($"IndexOf 'o' : {greeting.IndexOf("o")}"); //IndexOf 'o' : 1
            WriteLine($"IndexOf 'z' : {greeting.IndexOf("z")}"); //IndexOf 'o' : 6
            
            //LastIndexOf()
            WriteLine($"LastIndexOf 'Good' : {greeting.LastIndexOf("Good")}"); //LastIndexOf 'Good' : 0
            WriteLine($"LastIndexOf 'o' : {greeting.LastIndexOf("o")}"); //LastIndexOf 'o' : 6
            WriteLine($"LastIndexOf 'z' : {greeting.LastIndexOf("z")}"); //LastIndexOf 'z' : -1
            
            //StartsWith()
            WriteLine($"StartsWith 'Good' : {greeting.StartsWith("Good")}"); //StartsWith 'Good' : True
            WriteLine($"StartsWith 'Morning' : {greeting.StartsWith("Morning")}"); //StartsWith 'Morning' : False

            //EndsWith()
            WriteLine($"EndsWith 'Good' : {greeting.EndsWith("Good")}"); //EndsWith 'Good' : False
            WriteLine($"EndsWith 'Morning' : {greeting.EndsWith("Morning")}"); //EndsWith 'Morning' : True

            //Contains()
            WriteLine($"Contains 'Morning' : {greeting.Contains("Morning")}"); //Contains 'Morning' : True
            WriteLine($"Contains 'Evening' : {greeting.Contains("Evening")}"); //Contains 'Evening' : False

            //Replace()
            WriteLine($"Replaced 'Morning to Evening' : {greeting.Replace("Morning", "Evening")}"); //Replaced 'Morning to Evening' : Good Evening
        }
    }
}

 

(2) ๋ฌธ์ž์—ด ๋ณ€ํ˜•ํ•˜๊ธฐ

๋ฉ”์†Œ๋“œ ์„ค๋ช…
ToLower() ๋Œ€๋ฌธ์ž๋ฅผ ์†Œ๋ฌธ์ž๋กœ
ToUpper() ์†Œ๋ฌธ์ž๋ฅผ ๋Œ€๋ฌธ์ž๋กœ
Insert() ์ง€์ •๋œ ์œ„์น˜์— ํŠน์ • ๋ฌธ์ž์—ด ์‚ฝ์ž…
Remove() ์ง€์ •๋œ ์œ„์น˜๋กœ๋ถ€ํ„ฐ ์ง€์ •๋œ ์ˆ˜๋งŒํผ ๋ฌธ์ž ์‚ญ์ œ
Trim() ํ˜„์žฌ ๋ฌธ์ž์—ด์˜ ์•ž/๋’ค์— ์žˆ๋Š” ๊ณต๋ฐฑ์„ ์‚ญ์ œ
TrimStart() ํ˜„์žฌ ๋ฌธ์ž์—ด์˜ ์•ž์— ์žˆ๋Š” ๊ณต๋ฐฑ์„ ์‚ญ์ œ
TrimEnd() ํ˜„์žฌ ๋ฌธ์ž์—ด์˜ ๋’ค์— ์žˆ๋Š” ๊ณต๋ฐฑ์„ ์‚ญ์ œ
using System;
using System.Text;
using static System.Console;

namespace Hello
{
    class MainApp
    {
        static void Main(string[] args)
        {
            string str = " NoSpace ";

            WriteLine($"ToLower():{str.ToLower()}"); //ToLower(): nospace
            WriteLine($"ToUpper():{str.ToUpper()}"); //ToUpper(): NOSPACE
            WriteLine($"Insert():{str.Insert(3," lovely ")}"); //Insert(): No lovely Space
            WriteLine($"Remove():{str.Remove(3,2)}"); //Remove(): Noace
            WriteLine($"Trim():{str.Trim()}"); //Trim():NoSpace
            WriteLine($"TrimStart():{str.TrimStart()}"); //TrimStart():NoSpace
            WriteLine($"TrimEnd():{str.TrimEnd()}"); //TrimEnd(): NoSpace
        }
    }
}

 

(3) ๋ฌธ์ž์—ด ๋ถ„ํ• ํ•˜๊ธฐ

๋ฉ”์†Œ๋“œ ์„ค๋ช…
Split() ์ง€์ •๋œ ๋ฌธ์ž๋ฅผ ๊ธฐ์ค€์œผ๋กœ ํ˜„์žฌ ๋ฌธ์ž์—ด์„ ๋ถ„๋ฆฌํ•œ ๋‹ค์Œ ๋ถ„๋ฆฌํ•œ ๋ฌธ์ž์—ด์˜ ๋ฐฐ์—ด์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค
SubString() ์ง€์ •๋œ ์œ„์น˜๋กœ๋ถ€ํ„ฐ ์ง€์ •๋œ ์ˆ˜๋งŒํผ์˜ ๋ฌธ์ž๋กœ ์ด๋ฃจ์–ด์ง„ ์ƒˆ ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค
using System;
using System.Text;
using static System.Console;

namespace Hello
{
    class MainApp
    {
        static void Main(string[] args)
        {
            string greeting = "Good-Morning.";
            string greet = "Hi Hello Bye";

            WriteLine(greeting.Substring(0,5)); //Good-
            WriteLine(greeting.Substring(5)); //Morning.

            string[] arr = greet.Split(new string[] {" "},StringSplitOptions.None);
            WriteLine($"Word Count: {arr.Length}"); //Word Count: 3
            foreach (string element in arr)
                WriteLine($"{element}");
            /*
            Hi
            Hello
            Bye
             */
        }
    }
}

(4) ๋ฌธ์ž์—ด ์„œ์‹๋งž์ถ”๊ธฐ : ๋ฌธ์ž์—ด ์„œ์‹ํ™”์— ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ• ๋‘ ๊ฐ€์ง€,

์ฒซ๋ฒˆ์งธ๋Š” string ํ˜•์‹์˜ Format() ๋ฉ”์†Œ๋“œ์ด๊ณ , ๋˜ ๋‹ค๋ฅธ ํ•˜๋‚˜๋Š” ๋ฌธ์ž์—ด ๋ณด๊ฐ„

๋‘ ๋ฐฉ๋ฒ• ๋ชจ๋‘ ๋ฌธ์ž์—ด ํ‹€์„ ๋‘๊ณ , ๊ทธ ํ‹€์„ ์ด์šฉํ•ด์„œ ์„œ์‹ํ™”๋œ ์ƒˆ๋กœ์šด ๋ฌธ์ž์—ด์„ ๋งŒ๋“ค์–ด๋‚ธ๋‹ค๋Š” ๊ณตํ†ต์ ์ด ์žˆ๋‹ค. 

 

            WriteLine("์ œ๋ชฉ : {0}","์ด๊ฒƒ์ด C#์ด๋‹ค."); -> ์„œ์‹ ํ•ญ๋ชฉ์˜ ์ฒจ์ž๋งŒ ์ด์šฉํ•œ ๊ฒฝ์šฐ

 

๋ฌธ์ž์—ด ํ‹€์— ์ž…๋ ฅํ•˜๋Š” {0}, {1} .. ๋ฅผ ์ผ์ปซ์–ด "์„œ์‹ ํ•ญ๋ชฉ"์ด๋ผ๊ณ  ํ•œ๋‹ค.

์ด ์„œ์‹ ํ•ญ๋ชฉ์—์„œ ์ถ”๊ฐ€ ์˜ต์…˜์„ ์ž…๋ ฅํ•จ์œผ๋กœ์จ ๋” ๋‹ค์–‘ํ•œ ์„œ์‹ํ™”๋ฅผ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค. '

{์ฒจ์ž, ๋งž์ถค : ์„œ์‹ ๋ฌธ์ž์—ด}

 

์ฒจ์ž: ์„œ์‹ ํ•ญ๋ชฉ์˜ ์ฒจ์ž

๋งž์ถค: ์™ผ์ชฝ/์˜ค๋ฅธ์ชฝ ๋งž์ถค

์„œ์‹ ๋ฌธ์ž์—ด: ๋ณ€ํ™˜ ์„œ์‹ ์ง€์ • ๋ฌธ์ž์—ด

            string result = string.Format("{0,-10}DEF","ABC");
            WriteLine(result); //ABC       DEF
            result = string.Format("{0,10}DEF", "ABC");
            WriteLine(result); //       ABCDEF

์„œ์‹ ๋ฌธ์ž์—ด์˜ {0}์— -10์ด๋ผ๋Š” ๋งž์ถค ์˜ต์…˜์„ ์ž…๋ ฅํ•ด์ฃผ๋ฉด

result๋Š” "ABC       DEF"๊ฐ€ ๋œ๋‹ค. "DEF"์•ž์— ๋ฌธ์ž 10๊ฐœ๊ฐ€ ๋“ค์–ด๊ฐˆ ๊ณต๊ฐ„์„ ๋งŒ๋“ค๊ณ  ์•ž(์™ผ์ชฝ)์—์„œ๋ถ€ํ„ฐ "ABC"๋ฅผ ์ฑ„์›Œ๋„ฃ์Œ

 

๋’ค๋ถ€ํ„ฐ ์ฑ„์šฐ๋Š” ์„œ์‹ํ™”๋Š” 10์นธ์˜ ๊ณต๊ฐ„์„ ๋งŒ๋“ค๊ณ 

์™ผ์ชฝ๋ถ€ํ„ฐ ์ฑ„์šธ ๋•Œ๋Š” -10์„ ์ž…๋ ฅํ•˜์ง€๋งŒ,

์˜ค๋ฅธ์ชฝ๋ถ€ํ„ฐ ์ฑ„์šธ ๋–„๋Š” - ๊ธฐํ˜ธ ์—†์ด 10๋งŒ ์ž…๋ ฅํ•˜๋ฉด ๋œ๋‹ค.

 

๋ฌธ์ž์—ด ์„œ์‹์„ ์™ผ์ชฝ/์˜ค๋ฅธ์ชฝ์œผ๋กœ ๋งž์ถ”๋Š” ํ”„๋กœ๊ทธ๋žจ์ด ์—ฌ๋Ÿฌ ๊ฐœ์˜ ํ•ญ๋ชฉ์„ ๊ฐ€์ง€๋Ÿฐํ•˜๊ฒŒ ์ถœ๋ ฅํ•  ํ•„์š”๊ฐ€ ์žˆ์„ ๋•Œ ํŠนํžˆ ์œ ์šฉ.

 -1- ์™ผ์ชฝ/ ์˜ค๋ฅธ์ชฝ ๋งž์ถค

 

string fmt = "{0,-20}{1,-15}{2,30}";

           {์ˆœ๋ฒˆ,(๋ถ€ํ˜ธ:์•žor๋’ค=์™ผ์ชฝ/์˜ค๋ฅธ์ชฝ ๋งž์ถค)์นธ์˜ ๊ฐฏ์ˆ˜}

using System;
using System.Collections.Generic;
using static System.Console;

namespace Hello
{
    class MainApp
    {
        static void Main(string[] args)
        {
            string fmt = "{0,-20}{1,-15}{2,30}";
            WriteLine(fmt, "Gamer", "Author", "Title");
            WriteLine(fmt, "Player", "Buthor", "Iron Man");
            WriteLine(fmt, "Enemy", "Cuthor", "This is C#");
            WriteLine(fmt, "GameManager", "Duthor", "The C Programming Language");
        }
    }
}

using System;
using System.Collections.Generic;
using static System.Console;

namespace Hello
{
    class MainApp
    {
        static void Main(string[] args)
        {
            string fmt = "{0,20}{1,15}{2,-30}";
            WriteLine(fmt, "Gamer", "Author", "Title");
            WriteLine(fmt, "Player", "Buthor", "Iron Man");
            WriteLine(fmt, "Enemy", "Cuthor", "This is C#");
            WriteLine(fmt, "GameManager", "Duthor", "The C Programming Language");
        }
    }
}

 

 -2- ๋‚ ์งœ ๋ฐ ์‹œ๊ฐ„ ์„œ์‹ํ™”

๋‚ ์งœ์™€ ์‹œ๊ฐ„์„ ํ‘œํ˜„ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” DateTime ํด๋ž˜์Šค๊ฐ€ ํ•„์š”ํ•˜๋‹ค. 

using System;
using System.Text;
using static System.Console;

namespace Hello
{
    class MainApp
    {
        static void Main(string[] args)
        {
            DateTime dt = new DateTime(2022, 02, 07, 05, 41, 01);
            WriteLine($"{dt}");
        }
    }
}

์ถœ๋ ฅ : ๊ตญ๊ฐ€ ๋ฐ ์ง€์—ญ ์„ค์ •์— ๋”ฐ๋ผ ๋‹ค๋ฅธ ๊ฒฐ๊ณผ ์ถœ๋ ฅ

2022-02-07 ์˜ค์ „ 5:41:01
using System;
using System.Text;
using static System.Console;

namespace Hello
{
    class MainApp
    {
        static void Main(string[] args)
        {
            DateTime dt = new DateTime(2022, 02, 07, 17, 48, 01);
            //12์‹œ๊ฐ„ ํ˜•์‹ 
            WriteLine("12์‹œ๊ฐ„ ํ˜•์‹{0:yyyy-MM-dd tt hh:mm:ss (ddd)}",dt);
            //24์‹œ๊ฐ„ ํ˜•์‹
            WriteLine("24์‹œ๊ฐ„ ํ˜•์‹{0:yyyy-MM-dd tt HH:mm:ss (ddd)}", dt);
            WriteLine("24์‹œ๊ฐ„ ํ˜•์‹{0:yy-M-d tt H:m:s (ddd)}", dt);
        }
    }
}

์ถœ๋ ฅ

12์‹œ๊ฐ„ ํ˜•์‹2022-02-07 ์˜คํ›„ 05:48:01 (์›”)
24์‹œ๊ฐ„ ํ˜•์‹2022-02-07 ์˜คํ›„ 17:48:01 (์›”)
24์‹œ๊ฐ„ ํ˜•์‹22-2-7 ์˜คํ›„ 17:48:1 (์›”)

using System.Globalization;์„ ์‚ฌ์šฉํ•˜๋ฉด ์˜์–ด ์‚ฌ์šฉ์ž์™€ ํ•œ๊ธ€ ์‚ฌ์šฉ์ž ๊ฐ๊ฐ์—๊ฒŒ ์•Œ๋งž์€ ํ‚ค์›Œ๋“œ๋ฅผ ๋ณด์—ฌ์ค„ ์ˆ˜ ์žˆ๋‹ค.

(ํ† ์š”์ผ vs Sat(ํ˜น์€ Saturday))

(์˜ค์ „ ์˜คํ›„ vs AM PM)

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

namespace Hello
{
    class MainApp
    {
        static void Main(string[] args)
        {

            DateTime dt = new DateTime(2022, 02, 07, 17, 48, 01);
            //12์‹œ๊ฐ„ ํ˜•์‹ 
            WriteLine("12์‹œ๊ฐ„ ํ˜•์‹{0:yyyy-MM-dd tt hh:mm:ss (ddd)}",dt);
            //24์‹œ๊ฐ„ ํ˜•์‹
            WriteLine("24์‹œ๊ฐ„ ํ˜•์‹{0:yyyy-MM-dd tt HH:mm:ss (ddd)}", dt);
            WriteLine("24์‹œ๊ฐ„ ํ˜•์‹{0:yy-M-d tt H:m:s (ddd)}", dt);

            CultureInfo ciko = new System.Globalization.CultureInfo("ko-KR");
            WriteLine(dt.ToString("yyyy-MM-dd tt hh:mm:ss (ddd)",ciko));

            CultureInfo ciEn = new System.Globalization.CultureInfo("en-US");
            WriteLine(dt.ToString("yyyy-MM-dd tt hh:mm:ss (ddd)", ciEn));
        }
    }
}

์ถœ๋ ฅ

12์‹œ๊ฐ„ ํ˜•์‹2022-02-07 ์˜คํ›„ 05:48:01 (์›”)
24์‹œ๊ฐ„ ํ˜•์‹2022-02-07 ์˜คํ›„ 17:48:01 (์›”)
24์‹œ๊ฐ„ ํ˜•์‹22-2-7 ์˜คํ›„ 17:48:1 (์›”)
2022-02-07 ์˜คํ›„ 05:48:01 (์›”)
2022-02-07 PM 05:48:01 (Mon)

์ตœ์ข…

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace Hello
{
    class MainApp
    {
        static void Main(string[] args)
        {
            DateTime dt = new DateTime(2022, 02, 07, 18, 09, 01);
            WriteLine("12์‹œ๊ฐ„ ํ˜•์‹: {0:yyyy-MM-dd tt hh:mm:ss(ddd)}",dt);
            WriteLine("24์‹œ๊ฐ„ ํ˜•์‹: {0:yyyy-MM-dd HH:mm:ss(dddd)}", dt);

            CultureInfo ciko = new CultureInfo("ko-KR");
            WriteLine(dt.ToString("yyyy-MM-dd tt hh:mm:ss (ddd)", ciko));
            WriteLine(dt.ToString("yyyy-MM-dd HH:mm:ss (dddd)", ciko));
            WriteLine(dt.ToString(ciko));

            CultureInfo ciEn = new CultureInfo("en-US");
            WriteLine(dt.ToString("yyyy-MM-dd tt hh:mm:ss (ddd)", ciEn));
            WriteLine(dt.ToString("yyyy-MM-dd HH:mm:ss (dddd)", ciEn));
            WriteLine(dt.ToString(ciEn));
        }
    }
}

์ถœ๋ ฅ

12์‹œ๊ฐ„ ํ˜•์‹: 2022-02-07 ์˜คํ›„ 06:09:01(์›”)
24์‹œ๊ฐ„ ํ˜•์‹: 2022-02-07 18:09:01(์›”์š”์ผ)
2022-02-07 ์˜คํ›„ 06:09:01 (์›”)
2022-02-07 18:09:01 (์›”์š”์ผ)
2022-02-07 ์˜คํ›„ 6:09:01
2022-02-07 PM 06:09:01 (Mon)
2022-02-07 18:09:01 (Monday)
2/7/2022 6:09:01 PM

 -3- ๋ฌธ์ž์—ด ๋ณด๊ฐ„

 

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace Hello
{
    class MainApp
    {
        static void Main(string[] args)
        {
            int n = 123;
            WriteLine($"{(n>100?"ํผ":"์ž‘์Œ")}"); //ํผ
        }
    }
}

 

 

์ตœ์ข… ์†Œ์Šค์ฝ”๋“œ

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace Hello
{
    class MainApp
    {
        static void Main(string[] args)
        {
            string name = "๋ฐ•๋‹จ๋‹จ";
            int age = 23;
            WriteLine($"{name,-10},{age:D3}");

            name = "๋ฐ•์—ฐ์•ฝ";
            age = 33;
            WriteLine($"{name},{age,-10:D3}");

            name = "๋ฐ•์ดˆ์›”";
            age = 28;
            WriteLine($"{name},{(age>19 ? "์„ฑ์ธ" :"๋ฏธ์„ฑ๋…„์ž")}");

        }
    }
}
๋ฐ•๋‹จ๋‹จ       ,023
๋ฐ•์—ฐ์•ฝ,033
๋ฐ•์ดˆ์›”,์„ฑ์ธ

์—ฐ์Šต ๋ฌธ์ œ ํ’€์ด

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace Hello
{
    class MainApp
    {
        static void Main(string[] args)
        {
            WriteLine("์‚ฌ๊ฐํ˜•์˜ ๋„ˆ๋น„๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”.");
            string width = ReadLine();
            int wid = int.Parse(width);
            WriteLine("์‚ฌ๊ฐํ˜•์˜ ๋†’์ด๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”.");
            string height = ReadLine();
            int hei = int.Parse(height);
            WriteLine($"๋„ˆ๋น„๋Š” {width}, ๋†’์ด๋Š” {height}์ด๋ฏ€๋กœ, ์‚ฌ๊ฐํ˜•์˜ ๋„ˆ๋น„๋Š”{wid* hei} ์ž…๋‹ˆ๋‹ค.");
        }
    }
}

์ถœ๋ ฅ ๊ฒฐ๊ณผ

์‚ฌ๊ฐํ˜•์˜ ๋„ˆ๋น„๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”.
30
์‚ฌ๊ฐํ˜•์˜ ๋†’์ด๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”.
40
๋„ˆ๋น„๋Š” 30, ๋†’์ด๋Š” 40์ด๋ฏ€๋กœ, ์‚ฌ๊ฐํ˜•์˜ ๋„ˆ๋น„๋Š”1200 ์ž…๋‹ˆ๋‹ค.
728x90

'C# > ์ด๊ฒƒ์ด C#์ด๋‹ค' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

12. ๋น„ํŠธ ์—ฐ์‚ฐ์ž  (0) 2022.02.08
11. null ์กฐ๊ฑด๋ถ€ ์—ฐ์‚ฐ์ž  (0) 2022.02.08
9. ๊ณต์šฉ ํ˜•์‹ ์‹œ์Šคํ…œ  (0) 2022.02.07
8. Var, Object ํ˜•์‹๊ณผ์˜ ์ฐจ์ด?  (0) 2022.02.07
7. Nullable, HasValue, Value  (0) 2022.02.07
    'C#/์ด๊ฒƒ์ด C#์ด๋‹ค' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€
    • 12. ๋น„ํŠธ ์—ฐ์‚ฐ์ž
    • 11. null ์กฐ๊ฑด๋ถ€ ์—ฐ์‚ฐ์ž
    • 9. ๊ณต์šฉ ํ˜•์‹ ์‹œ์Šคํ…œ
    • 8. Var, Object ํ˜•์‹๊ณผ์˜ ์ฐจ์ด?
    Rainbow๐ŸŒˆCoder
    Rainbow๐ŸŒˆCoder
    ๋ชฐ๋ผ๋„ ๊ฒฐ๊ตญ์€ ์•„๋Š” ๊ฐœ๋ฐœ์ž, ๊ทธ๋Ÿฐ ์‚ฌ๋žŒ์ด ๋˜๊ธฐ ์œ„ํ•œ ๋งค์ผ์˜ ํ•œ๊ฑธ์Œ

    ํ‹ฐ์Šคํ† ๋ฆฌํˆด๋ฐ”