我正在尝试删除某些字符。并修剪列表中的项目。这是我的问题的简单说明。
private void add_Click(object sender, EventArgs e)
{
string[] s = { "Tarik \"F\"", "Tarik ", "Tarik", "Souad ", "Mehdi FARID", "Souad F ", "DAFIR CCF", "khalid FA", "SAFAF" };
char[] c = { 'F', ' ', '"' };
foreach (string b in s)
{
txtDisplay.AppendText(b.TrimEnd(c) + "\n");
}
}
结果是:
Tarik,
Tarik,
Tarik,
Souad,
Mehdi FARID,
Souad,
DAFIR CC: (for this item I want to keep the last 'F'),
SAFA : (for this item I want to keep the last 'F')
这个想法是,如果 char 'F' 是单词的一部分,它不能被删除,如果是孤立的,那么是的。