# C# 字串切割與合併 ###### tags: `程式設計` `C#` ## 範例 https://dotnetfiddle.net/SOHICA ```=C# // 字串合併 // 參考 https://dotblogs.com.tw/ajun/2009/03/08/7408 string[] arr = new string[3]; arr[0] = "abc"; arr[1] = "def"; arr[2] = "ghi"; //在join的第一格放入要分隔的符號 string commaStr = string.Join(",", arr); Console.WriteLine(commaStr); string verticalbarStr = string.Join("|", arr); Console.WriteLine(verticalbarStr); //分割字串,用逗號 //印出來的時候,每個 切割結束處 加上逗點 string[] sArray = Regex.Split(commaStr,",",RegexOptions.IgnoreCase); foreach (string i in sArray) Console.WriteLine(i.ToString()); ``` ## 參考文件 * [c# tips] 加入分隔字元 https://dotblogs.com.tw/ajun/2009/03/08/7408 * c#中Split 分離字元以及空格消除方法https://www.itread01.com/content/1550062652.html * C#幾種擷取字串的方法(split 、Substring、Replace、remove) https://www.itread01.com/content/1547376312.html
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up