本文介绍了如何仅删除一个字符C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ex

列表框

我的名字
她的名字
你的名字.

我只想删除."

我的名字
她的名字
你的名字

从非解决方案中移出

ex

Listbox

my name
her name
your name.

I want to remove only "."

my name
her name
your name

Moved from non-solution

string[] dataFromFile = lstQiftet.Items.Cast<string>().ToArray();

           ArrayList arr = new ArrayList();

           foreach (string s in dataFromFile)




我尝试了s.remove(.";).... s.TrimEnd(.")......不起作用
[/Edit]




I tried s.remove(".";).... s.TrimEnd(".")...... dont work
[/Edit]

推荐答案

for (int i = 0, count = dataFromFile.Length; i != count; ++i)
{
    dataFromFile[i] = dataFromFile[i].TrimEnd('.');
} 


void Main()
{
    Form form1 = new Form();
    ListBox listBox1 = new ListBox();
    listBox1.Items.AddRange(new string[]{"my name","her name","your name.  "});
    form1.Controls.Add(listBox1);
    form1.ShowDialog();

    //Convert to ToList to set DataSource property of ListBox
    //Trim() is required to remove the extra space for the TrimEnd to work on .
    var items = listBox1.Items.Cast<string>().Select (s => s.TrimEnd(new char[]{'.',' '})).ToList();

    //This will not compile as Items  property is read only.
    //listBox1.Items = items;

    listBox1.DataSource=items;
    form1.ShowDialog();
}


s.Replace(".", "");


这篇关于如何仅删除一个字符C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 12:08
查看更多