如何将字符串文本添加到获取string []的方法中?

时间:2014-01-27 07:25:15

标签: c# winforms

我的这个字符串里面包含文字:

readableRss = RssReader.covertRss("http://rotter.net/rss/rotternews.xml");

readbleRss是一个字符串变量。

然后我有了这段代码:

SetupText(new string[] { "Hello everyone this is the weather for today", "Text2", "hello world this is a test for long text what do you think", "Text 4 -> 4", "Text Nr. 5" });
SetupColors(new Color[] { Color.Blue, Color.Lime, Color.Maroon, Color.FromArgb(255, 71, 71, 255), Color.BurlyWood });

private void SetupColors(Color[] colors)
{
      if (this.newsFeed1.TextColor.Length > 0 && colors.Length > 0)
             this.newsFeed1.TextColor[0] = colors[0];
      if (this.newsFeed1.TextColor.Length > 1 && colors.Length > 1)
             this.newsFeed1.TextColor[1] = colors[1];
      if (this.newsFeed1.TextColor.Length > 2 && colors.Length > 2)
             this.newsFeed1.TextColor[2] = colors[2];
      if (this.newsFeed1.TextColor.Length > 3 && colors.Length > 3)
             this.newsFeed1.TextColor[3] = colors[3];
      if (this.newsFeed1.TextColor.Length > 4 && colors.Length > 4)
             this.newsFeed1.TextColor[4] = colors[4];
}

private void SetupText(string[] textToDisplay)
    {
         if (this.newsFeed1.NewsTextFeed.Length > 0 && textToDisplay.Length > 0)
              this.newsFeed1.NewsTextFeed[0] = textToDisplay[0];
          if (this.newsFeed1.NewsTextFeed.Length > 1 && textToDisplay.Length > 1)
              this.newsFeed1.NewsTextFeed[1] = textToDisplay[1];
          if (this.newsFeed1.NewsTextFeed.Length > 2 && textToDisplay.Length > 2)
              this.newsFeed1.NewsTextFeed[2] = textToDisplay[2];
          if (this.newsFeed1.NewsTextFeed.Length > 3 && textToDisplay.Length > 3)
              this.newsFeed1.NewsTextFeed[3] = textToDisplay[3];
          if (this.newsFeed1.NewsTextFeed.Length > 4 && textToDisplay.Length > 4)
              this.newsFeed1.NewsTextFeed[4] = textToDisplay[4];
    }

我想要的是改为向新闻传送器添加来自SetupText的文本(new string [] { 从readableRss

添加文本

我的程序使文本像动画新闻一样从动画中向下滚动。

该网站是rss feed网站。 所以我希望用我的代码滚动rss中的每一行。

这是变量readbleRss中格式的示例:

אם הרב אלקנה אליאסי נרצח ברקע לאומני?
Mon, 27 Jan 2014 10:27:40 +0200

ביל גייטס הובס תוך דקה ע''י צעיר בן 23 במשחק שחמט
Mon, 27 Jan 2014 10:25:30 +0200

מי יציל את המוסד לביטוח לאומי? - החל מ2042 לא יישאר כסף לקצבאות
Mon, 27 Jan 2014 10:25:03 +0200

编辑**

这是我现在尝试的但它不起作用我在运行程序时看不到任何文字:

readableRss = RssReader.covertRss("http://rotter.net/rss/rotternews.xml");
            for (int i = 0; i < readableRss.Length; i++)
            {
                this.newsFeed1.NewsTextFeed = new string[i];
                string t = Convert.ToString(readableRss[i]);
                SetupText(new string[] { t });
            }
            this.newsFeed1.TextColor = new Color[1];
            SetupColors(new Color[] { Color.Blue });

1 个答案:

答案 0 :(得分:1)

如果您想按行分割字符串,可以使用此

string[] lines = Regex.Split(readableRss, "\r\n");

当然,您需要包含相应的命名空间。

using System.Text.RegularExpressions;

希望这有帮助。