C# 如何将字符串文本添加到获取字符串[]的方法中?
我有一个包含文本的字符串:C# 如何将字符串文本添加到获取字符串[]的方法中?,c#,winforms,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
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(新字符串[]{
从readableRss添加文本的步骤
我的程序使文本在动画中从下向上滚动,就像新闻馈送器一样
该网站是rss源网站。
因此,我希望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 });
readableRss=RssReader.covertRss(“http://rotter.net/rss/rotternews.xml");
for(int i=0;i
如果要按行分割字符串,可以使用此
string[] lines = Regex.Split(readableRss, "\r\n");
当然,您需要包含相应的名称空间
using System.Text.RegularExpressions;
希望这有帮助。
这可能是由<代码> RSSRealCudio.CurrTSUTSH(/Cuth>)返回的字符串如何?考虑将其拆分或创建一个方法来接受<代码> String < /C> >(将其放入<代码>随机或<代码>第一次/代码>或<代码>下< /COD>滚动字段,取决于您想要什么)。.用我目前尝试的内容更新了我的问题,但不起作用。this.newsFeed1.NewsTextFeed=newstring[i]
-有一个问题。每次循环迭代时,都会将新字符串数组分配给NewsTextFeed
。我认为您不想这样做-尝试将字符串数组初始化为循环外部的大小readableRss
。循环完成后,调用SetupText
。执行readableRss.Length在FOR循环中不好。我需要以某种方式循环readableRss中的行数。在我的问题中,我添加了变量readableRss的内容示例。每个带有日期和时间的文本行就像控件中的一行应该向上移动一样。