2
我有字符串我想用連續的數字格式的字符串,我做了什麼有格式化並建立連續的數字
int i =0
String res = String.Foramt("text {0} text {1} {2} {3} {4} ...", i
,i+1 , i+2, i+3, i+4)
是這樣,使用正則表達式或LINQ的字符串操作更優雅的方式?
我有字符串我想用連續的數字格式的字符串,我做了什麼有格式化並建立連續的數字
int i =0
String res = String.Foramt("text {0} text {1} {2} {3} {4} ...", i
,i+1 , i+2, i+3, i+4)
是這樣,使用正則表達式或LINQ的字符串操作更優雅的方式?
string res2 = string.Format(
"text {0} text {1} {2} {3} {4} ...",
Enumerable.Range(0, 5).OfType<object>().ToArray());
string.Format需要對象數組參數。
有許多不同的方法來做到這一點,但我覺得
String.Join(" ", Enumerable.Range(0, 4))
是你想達到什麼樣的不夠優雅。
這不起作用 –
從何種意義上說?它產生一個字符串,數字之間用空格隔開。你可以將它作爲最後一個參數傳遞給你的String.format。 – Evk