如何为富文本框中的每一行重复此操作?(How to repeat this for every line in rich text box?)

编程入门 行业动态 更新时间:2024-10-13 14:27:01
何为富文本框中的每一行重复此操作?(How to repeat this for every line in rich text box?)

我目前正在使自己成为一个小工具。

基本上我有这个列表,如下所示:

NPWR00160_00 LittleBigPlanet NPWR00163_00 Warhawk NPWR00179_00 Pure NPWR00180_00 Midnight Club: Los Angeles NPWR00181_00 echochrome™ NPWR00187_00 WipEout® HD

这当前输入到richTextBox中。

我正在尝试这样做,获取该行的NPWRXXXXXX并将其保存为字符串,然后将游戏名称保存为另一个字符串,我可以继续并执行我原本要做的事情。 但是对于richTextBox的每一行,它继续如上所述。

不太确定如何从richTextBox获取一行并将其保存为字符串,我可以在其中为richTextBox的每一行重复该过程。

对于我的尝试,我给自己一个例子,字符串是NPWR02727_00 Skydive:Proximity Flight。 我做的是这样的:

string game = "NPWR02727_00 Skydive: Proximity Flight"; string NPWR = game.Substring(0,13); string gamename = game.Remove(0, 13); richTextBox2.AppendText("NPWRID: " + NPWR + " Game: " + gamename + Environment.NewLine);

这实际上成功地保存了字符串并将其作为新表单写在第二个文本框中。

唯一的问题是我不确定如何从RichTextBox转换一行并将其转换为字符串,并为富文本框中的每一行重复该过程

编辑

所以我发现了如何将字符串从richTextBox转换为一行。

string line = richTextBox1.Lines[0];

所以这将获得第一行并将其保存为字符串“line”

现在将代码更新为

string game = richTextBox1.Lines[0]; string NPWR = game.Substring(0,13); string gamename = game.Remove(0, 13); richTextBox2.AppendText("NPWRID: " + NPWR + " Game: " + gamename + Environment.NewLine);

现在我如何让每一行都能运行这段代码,我知道我需要一些东西来重复它,还有什么要改变0 ,每次重复时都要加1?

再次编辑

真棒,忘记上面的编辑,非常感谢!

I am currently making myself a little tool.

Essentially I have this list which goes like this:

NPWR00160_00 LittleBigPlanet NPWR00163_00 Warhawk NPWR00179_00 Pure NPWR00180_00 Midnight Club: Los Angeles NPWR00181_00 echochrome™ NPWR00187_00 WipEout® HD

This is currently typed into a richTextBox.

I am trying to do this, get the NPWRXXXXXX of the line and save it as a string, and then the Games Name and save that as another string for which I can go ahead and do what I was originially going to do with it. But for each line of the richTextBox which carries on with that formation as above.

Not too sure how to get a line from the richTextBox and save it as a string, in which I can repeat that process for every single line of the richTextBox.

For what I have tried, I gave myself an example that the string was NPWR02727_00 Skydive: Proximity Flight. What I did was this:

string game = "NPWR02727_00 Skydive: Proximity Flight"; string NPWR = game.Substring(0,13); string gamename = game.Remove(0, 13); richTextBox2.AppendText("NPWRID: " + NPWR + " Game: " + gamename + Environment.NewLine);

Which actually does successfully save the strings and write it in the second text box as the new form.

Only issue is I'm not sure how to convert a line from the RichTextBox and turn it into a string, and repeat the process for each line in the rich text box

EDIT

So I found out how to turn a string into a line from the richTextBox..

string line = richTextBox1.Lines[0];

So this will get the first line and save it as the string "line"

This now updates the code to

string game = richTextBox1.Lines[0]; string NPWR = game.Substring(0,13); string gamename = game.Remove(0, 13); richTextBox2.AppendText("NPWRID: " + NPWR + " Game: " + gamename + Environment.NewLine);

Now how do I get this code to run for every line, I understand I need something to repeat it, and something to change the 0 to count up by 1 everytime it repeats?

EDIT AGAIN

Awesome, forget the above edit, thanks a lot!

更多推荐

本文发布于:2023-07-27 20:23:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1295029.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:何为   框中   文本   操作   repeat

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!