我有一个像这样的字符串:
string word="HELLO";
Run Code Online (Sandbox Code Playgroud)
并清除字符串索引,如下所示:
IList<string> clearIndexes = indexes;// for example {2,4}
Run Code Online (Sandbox Code Playgroud)
我想要的是什么
*E*L*// the 2th and 4th elements are clear and the other should be shown with *,
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
这是一种需要List<string>索引的方法
string word = "HELLO";
List<string> clearIndexes = new List<string> { "2", "4" };
string result = new string(word.Select((c, i) => !clearIndexes.Contains((i+1).ToString()) ? '*' : c).ToArray());
Run Code Online (Sandbox Code Playgroud)
通常索引开始0于此我添加(i+1)以获得结果*E*L*
| 归档时间: |
|
| 查看次数: |
77 次 |
| 最近记录: |