C# 程式以拆分 Windows 目錄中的部分


首先,設定一個字串,即你的 Windows 目錄路徑 −

string str = @"D:\Downloads\Amit";

現在使用 Split() 方法,在出現 \ 的任何地方進行拆分 −

str.Split(' \')

以下是完整程式碼 −

示例

 實際演示

using System;
class Program {
   static void Main() {
      string str = @"D:\Downloads\Amit";
      Console.WriteLine("Directory...
"+str);       string[] myStr = str.Split('\');       Console.WriteLine("
Split...");       foreach (string ch in myStr) {          Console.WriteLine(ch);       }    } }

輸出

Directory...
D:\Downloads\Amit

Split...
D:
Downloads
Amit

更新於: 22-Jun-2020

558 次瀏覽

開啟你的 職業生涯

完成課程,獲得認證

開始
廣告
© . All rights reserved.