string input = "example:text"; // 你的輸入字串 int colonIndex = input.IndexOf(':'); // 找到 ':' 的索引 if (colonIndex != -1) // 確保找到了 ':' { string result = input.Substring(colonIndex + 1); // 取得 ':' 後的字串 Console.WriteLine(result); // 輸出結果 } else { Console.WriteLine("':' 字元未找到"); }
string input = "example:text"; // 你的輸入字串 string[] parts = input.Split(':'); // 根據 ':' 分割字串 if (parts.Length > 1) // 確保有 ':' 的存在 { string result = parts[1]; // 取得 ':' 後的部分 Console.WriteLine(result); // 輸出結果 } else { Console.WriteLine("':' 字元未找到"); }
string input = "example:text:moretext"; // 你的輸入字串 int lastColonIndex = input.LastIndexOf(':'); // 找到最後一個 ':' 的索引 if (lastColonIndex != -1) // 確保找到了 ':' { string result = input.Substring(lastColonIndex + 1); // 取得最後一個 ':' 後的字串 Console.WriteLine(result); // 輸出結果 } else { Console.WriteLine("':' 字元未找到"); }