C#

[C#]IndexOf() 문자열을 찾아 위치를 반환한다.

데브프로그라 2024. 2. 22. 22:08
반응형

int IndexOf(string strSearchText)

- strSearchText : 찾고자하는 문자열 입력

- 반환(return) 값 

  -1 : 문자열 찾지 못함

   5 : 숫자 (문자열의 위치를 숫자로 반환)

 

using System;
namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = "Sample Test";
            int index = str.IndexOf("Test");
            Console.WriteLine(index.ToString());

            Console.WriteLine(str.Substring(index));
        }
    }
}

 

결과 : 7

"Test"

반응형

/* 코드복사 버튼 */ pre { position: relative; overflow: visible; } pre .copy-button { opacity: 0; position: absolute; right: 8px; top: 4px; padding: 6px 18px; color: rgb(255, 255, 255); background: rgba(255, 223, 0, 0.6); border-radius: 5px; transition: opacity .3s ease-in-out; } pre:hover .copy-button { opacity: 1; } pre .copy-button:hover { color: #eee; transition: all ease-in-out 0.3s; } pre .copy-button:active { color: #33f; transition: all ease-in-out 0.1s; } .copy-message:before { content: attr(copy-message); position: absolute; left: -95px; top: 0px; padding: 6px 18px; color: #fff; background: rgba(255, 223, 0, 0.6); border-radius: 5px; } /* 코드복사 버튼 END */