Replace all occurences of a string from a string array

前端 未结 8 1446
伪装坚强ぢ
伪装坚强ぢ 2020-12-11 16:49

I have a string array like:

 string [] items = {\"one\",\"two\",\"three\",\"one\",\"two\",\"one\"};

I would like to replace all ones with z

8条回答
  •  渐次进展
    2020-12-11 16:54

    Theres no way to do that without looping.. even something like this loops internally:

    string [] items = {"one","two","three","one","two","one"};
    
    string[] items2 = items.Select(x => x.Replace("one", "zero")).ToArray();
    

    I'm not sure why your requirement is that you can't loop.. however, it will always need to loop.

提交回复
热议问题