我有一个看起来像这样的 RichTextBox
:
TEXT NEXT_TEXT 10.505 -174.994 0
TEXT NEXT_TEXT 100.005 174.994 90
TEXT NEXT_TEXT -10.000 -5.555 180
TEXT NEXT_TEXT -500.987 5.123 270
TEXT NEXT_TEXT 987.123 1.000 180
TEXT NEXT_TEXT 234.567 200.999 90
我想用任何东西替换 "." 并将其放入 ListBox
...
所以新文件看起来像这样:
TEXT NEXT_TEXT 10505 -174994 0
TEXT NEXT_TEXT 100005 174994 90
TEXT NEXT_TEXT -10000 -5555 180
TEXT NEXT_TEXT -500987 5123 270
TEXT NEXT_TEXT 987123 1000 180
TEXT NEXT_TEXT 234567 200999 90
我考虑过将这些值乘以 1000,但我不知道如何正确地对字符串进行匹配计算。
所以下一个想法是这样做(但是这行不通):
// Splits the lines in the rich text boxes
string[] listOneLines = oneRichTextBox.Text.Split('\n');
// Set the selection mode to multiple and extended.
placementOneListBox.SelectionMode = SelectionMode.MultiExtended;
// Shutdown the painting of the ListBox as items are added.
placementOneListBox.BeginUpdate();
// Display the items in the listbox.
foreach (var item in listOneLines)
{
item.Replace(".","");
placementOneListBox.Items.Add(item);
}
// Allow the ListBox to repaint and display the new items.
placementOneListBox.EndUpdate();
- 谁能帮我弄清楚如何替换“.”?
最佳答案
字符串是不可变的,所以这一行是错误的:
item.Replace(".","");
这将返回替换后的字符串,但 item
未更改。你需要这个:
foreach (var item in listOneLines)
placementOneListBox.Items.Add(item.Replace(".",""));
关于C# - 将字符替换为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6836156/