0
其它添加到頂部第一次看到的列表:爲什麼我將一個新項目添加到列表中<string>它將它添加到列表的底部?
但在第一時間上的下一個次後一個新的項被添加至底部,並我希望它在最上面。 反而是6號的新項目應該是1和6號
這是我每次加建清單3項:
newText.Add(t[i]);
newText.Add(dateTime[i]);
newText.Add(string.Empty);
然後我做一個過濾器,以匹配特定字符串(詞):
FilterWords.CheckIfWordsExistInList(newText);
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using mshtml;
using System.IO;
namespace ScrollLabelTest
{
class FilterWords
{
public static void CheckIfWordsExistInList(List<string> newText)
{
// start at the bottom in the first line "that matters" and go down by 3
for (int x = newText.Count - 3; x >= 0; x -= 3)
{
// check if the line contains any of the words specified
if (!WordsList.words.Any(w => newText[x].Contains(w)) || newText[x] == "")
{
// remove the checked line as well as the next two if not
newText.RemoveRange(x, 3);
}
}
ExtractLinks.CheckIfResponseContainWords();
}
}
}
然後在我有我給你把它從清單newText項目的字符串:
private void CombindedStringFix()
{
combindedString = string.Join(Environment.NewLine, newText);
string[] ss = combindedString.Split(new string[] { "\n", "\r\n" },
StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < ss.Length; i++)
ss[i] = ss[i].Trim();
combindedString = String.Join("\n", ss);
string[] lines = combindedString.Split(new string[] { "\n", "\r\n" },
StringSplitOptions.RemoveEmptyEntries);
combindedString = String.Empty;
for (int i = 0; i < lines.Length; i++)
{
if (i % 2 == 0)
combindedString += Environment.NewLine;
combindedString += lines[i].Trim() + Environment.NewLine;
}
scroller1.TextToScroll = combindedString;
m_textToScroll.Text = combindedString;
m_textToScroll.Text = m_textToScroll.Text.TrimStart();
}
但每次添加新文本時,我都會在底部的scroller1和m_textToScroll中看到它。
會使用'Stack'幫忙嗎?還是它實際上是想添加一組特定的,有限的值並且應該使用強類型模型? –
ClickRick