본문 바로가기

카테고리 없음

String.Concat / String.Join/Contain /IndexOf

반응형
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] animals = { "mouse", "cow", "tiger", "rabbit", "dragon" };
            foreach (var item in animals)
            {
                Console.Write(item+" ");
            }
            string s = string.Concat(animals); 
           Console.WriteLine("\n"+s);
            s = string.Join("," , animals);
            Console.WriteLine("\n" + s);

            string userName = "bikang";
            string date = DateTime.Today.ToShortDateString();
            Console.WriteLine(date);

            string s1 = "mouse, cow, tiger, rabbit, dragon";
            string s2 = "cow";
            bool b = s1.Contains(s2);
            for (int i = 0; i < s1.Length; i++)
            {
                if (b==true)
                {
                    Console.WriteLine(s2);
                    break;
                }

            }
            Console.WriteLine(b);
            if (b)
            {
                int index = s1.IndexOf(s2);
                
                 Console.WriteLine($"{s2} begin at index{index}");

                
            }
반응형