如何更改字符串格式。
MATCH (city1:City {name: 'Foo'})
OPTIONAL MATCH (st:Street {streetName: 'streetName1'})-[:BELONGS_TO]->(city1)
FOREACH(x IN CASE WHEN st IS NULL THEN [1] END |
CREATE (st2:Street {streetName: 'streetName1'})-[:BELONGS_TO]->(city1))
至
2,4,6,9
[2],[4],[6],[9]
结果我得到 int[] terms = termsList.ToArray();
var result = string.Join(",", terms);
,但我想得到2,4,6,9
格式
答案 0 :(得分:3)
那
string result = String.Join(",", terms.ToList().ConvertAll(i => "["+i.ToString()+"]"));
优雅的方法是
string result = String.Join(",", terms.Select(x => "[" + x + "]"));
我喜欢这个,
string result = string.Join(",", Array.ConvertAll(terms, s => $"[{s}]"));
POC:.net Fiddle
答案 1 :(得分:3)
您可以使用LINQ和字符串插值:
var terms = new []{ 2, 4, 6, 9 };
var str = string.Join(",", terms.Select(x => $"[{x}]"));
结果
[2],[4],[6],[9]