簡體   English   中英

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

[英]How can I add the string text to the method that get string[]?

我有此字符串,其中包含文本:

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 [] {的文本添加到readers

我的程序使文本在動畫中的滾動從新聞滾動到新聞滾動。

該網站是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 });

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

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

當然,您需要包括相應的名稱空間。

using System.Text.RegularExpressions;

希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM