複数の文字列を単一のコンマ区切り文字列に変換するC#プログラム
文字列を設定する-
List<string> val = new List<string>();
// list of strings
val.Add("water");
val.Add("food");
val.Add("air"); Joinメソッドを使用して、複数の文字列を単一のコンマ区切り文字列に変換します-
string.Join(",", val.ToArray()); これが完全なコードです-
例
using System;
using System.Collections.Generic;
public class Demo {
public static void Main() {
List<string> val = new List<string>();
// list of strings
val.Add("water");
val.Add("food");
val.Add("air");
string res = string.Join(",", val.ToArray());
Console.WriteLine(res);
}
} 出力
water,food,air
-
Python文字列をタプルに変換するにはどうすればよいですか?
Pythonの組み込み関数tuple()は、任意のシーケンスオブジェクトをタプルに変換します。文字列の場合、各文字は文字列として扱われ、コンマで区切られたタプルに挿入されます。 >>> string="Tutorialspoint" >>> tuple(string) ('T', 'u', 't', 'o', 'r', 'i', 'a', 'l', 's', 'p', 'o
-
Pythonで2つの文字列を結合して1つの文字列に変換するにはどうすればよいですか?
Pythonで2つの文字列を結合するには、連結演算子+を使用できます。例: str1 = "Hello" str2 = "World" str3 = str1 + str2 print str3 これにより、出力が得られます: HelloWorld str.join(seq)を使用して、複数の文字列を結合することもできます。例: s = "-"; seq = ("a", "b", "c"); # This is sequence of strings. print s.j