.NET/ListのStringをカンマ区切りにする方法
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
#navi(../)
* ListのStringをカンマ区切りにする方法 [#k101836e]
ListオブジェクトにAddメソッドなどを使って、文字列を複数追...
以下のサンプルコードで List<String> / List(Of String) を...
カンマ区切りのサンプルコードですが、カンマをパイプ(|)にす...
#contents
* 動作確認環境 [#l0f91152]
- Visual Studio 2022
- Windows 10 22H2
- Windows 11 22H2
- .NET 6.0
- コンソールアプリケーション
* サンプルコード [#g8d0658b]
以下は List に設定されている String(文字列)をカンマ区切...
1行目の出力はカンマ(,)区切り、~
2行目の出力はシングルクォーテーション(')で囲み出力してい...
String.Joinを使ってList<String> / List(Of String)をカンマ...
** C# [#t27d4e95]
namespace CommaSeparateCS
{
internal class Program
{
static void Main(string[] args)
{
List<string> list = new()
{
"elephant",
"giraffe",
"hippopotamus",
"Shoebill"
};
Console.WriteLine(String.Join(",", list));
Console.WriteLine("'" + String.Join("','", l...
}
}
}
** VB.NET [#t1fb4102]
Module Program
Sub Main(args As String())
Dim list As List(Of String) = New List(Of String...
"elephant",
"giraffe",
"hippopotamus",
"Shoebill"
}
Console.WriteLine(String.Join(",", list))
Console.WriteLine("'" + String.Join("','", list)...
End Sub
End Module
* 実行結果 [#v491b106]
実行すると以下のように出力されます。
elephant,giraffe,hippopotamus,Shoebill
'elephant','giraffe','hippopotamus','Shoebill'
以上、 List<String> / List(Of String) を指定した区切り文...
終了行:
#navi(../)
* ListのStringをカンマ区切りにする方法 [#k101836e]
ListオブジェクトにAddメソッドなどを使って、文字列を複数追...
以下のサンプルコードで List<String> / List(Of String) を...
カンマ区切りのサンプルコードですが、カンマをパイプ(|)にす...
#contents
* 動作確認環境 [#l0f91152]
- Visual Studio 2022
- Windows 10 22H2
- Windows 11 22H2
- .NET 6.0
- コンソールアプリケーション
* サンプルコード [#g8d0658b]
以下は List に設定されている String(文字列)をカンマ区切...
1行目の出力はカンマ(,)区切り、~
2行目の出力はシングルクォーテーション(')で囲み出力してい...
String.Joinを使ってList<String> / List(Of String)をカンマ...
** C# [#t27d4e95]
namespace CommaSeparateCS
{
internal class Program
{
static void Main(string[] args)
{
List<string> list = new()
{
"elephant",
"giraffe",
"hippopotamus",
"Shoebill"
};
Console.WriteLine(String.Join(",", list));
Console.WriteLine("'" + String.Join("','", l...
}
}
}
** VB.NET [#t1fb4102]
Module Program
Sub Main(args As String())
Dim list As List(Of String) = New List(Of String...
"elephant",
"giraffe",
"hippopotamus",
"Shoebill"
}
Console.WriteLine(String.Join(",", list))
Console.WriteLine("'" + String.Join("','", list)...
End Sub
End Module
* 実行結果 [#v491b106]
実行すると以下のように出力されます。
elephant,giraffe,hippopotamus,Shoebill
'elephant','giraffe','hippopotamus','Shoebill'
以上、 List<String> / List(Of String) を指定した区切り文...
ページ名: