본문 바로가기
개발/C#

유니티 C# 문자열 자르기 Substring, Split, Replace, IndexOf, Trim

by SPNK 2023. 3. 22.
반응형
  • Substring
string myString = "Hello World!";
string subString = myString.Substring(6, 5);
Debug.Log(subString); // Output: "World"

 

  • Split
string myString = "Hello, World!";
string[] substrings = myString.Split(',');
// Output: "Hello", " World!"

 

  • Replace
string myString = "Hello World!";
string replacedString = myString.Replace("Hello", "Hi");
Debug.Log(replacedString); // Output: "Hi World!"

 

  • IndexOf
string myString = "Hello World!";
int index = myString.IndexOf("World");
Debug.Log(index); // Output: 6

 

  • Trim
string myString = "   Hello, World!   ";
string[] substrings = myString.Trim().Replace(",", "").Split(' ');
// Output: "Hello", "World!"
반응형

댓글