获取文本框中每行的第二个单词以在命令中使用

发布于 2025-01-15 19:58:52 字数 1128 浏览 4 评论 0原文

我需要从文本框的用户输入中获取第二个单词,文本框包含多行,并且在每行中第二个单词需要在命令行参数中使用。我已经尝试过下面的方法,但是 grep 了所有内容并且也无法处理新行。

任何想法表示赞赏!

string secondaryword = textBox1.Text;

string\[\] split = secondaryword.Split(' ');

            for (int i = 0; i < split.Length; i++)
            {
                
                
                Process dmdevicehost1c1 = new Process();
                dmdevicehost1c1.StartInfo.FileName = "plink";
                dmdevicehost1c1.StartInfo.UseShellExecute = false;
                dmdevicehost1c1.StartInfo.CreateNoWindow = true;
                dmdevicehost1c1.StartInfo.Arguments = "user@<ip address> -batch -pw <password> mmlsnsd |grep datavol |grep" + split;
                dmdevicehost1c1.StartInfo.RedirectStandardOutput = true;
                dmdevicehost1c1.Start();
                textBox4.AppendText(dmdevicehost1c1.StandardOutput.ReadToEnd());`

在此处输入图像描述

我已附上文本框的图片及其格式。

我基本上需要它来 grep 每行的最后一个单词,并运行命令的次数与行数相同,所以一次使用第一行第二个单词,然后再次使用第二行第二个单词,依此类推。

i need to get the secord word from a users input from a TextBox, the textbox contains multiple lines and in each line the second word needs to be used in a commandline argument. i have tried the below but that greps everything and cant handle new line aswell.

any ideas appreciated!

string secondword = textBox1.Text;

string\[\] split = secondword.Split(' ');

            for (int i = 0; i < split.Length; i++)
            {
                
                
                Process dmdevicehost1c1 = new Process();
                dmdevicehost1c1.StartInfo.FileName = "plink";
                dmdevicehost1c1.StartInfo.UseShellExecute = false;
                dmdevicehost1c1.StartInfo.CreateNoWindow = true;
                dmdevicehost1c1.StartInfo.Arguments = "user@<ip address> -batch -pw <password> mmlsnsd |grep datavol |grep" + split;
                dmdevicehost1c1.StartInfo.RedirectStandardOutput = true;
                dmdevicehost1c1.Start();
                textBox4.AppendText(dmdevicehost1c1.StandardOutput.ReadToEnd());`

enter image description here

i've attached a picture of the textbox and how the format of it looks.

i basically need it to grep the last word of each line and run the command the same amount of times as there are lines, so one time with the first lines second word, then again with the second lines second word and so forth..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情泪▽动烟 2025-01-22 19:58:52
            // Create a string array and store the contents of the Lines property.
            string[] tempArray = textBox1.Lines;
            // Loop through the array and send the contents of the array to debug window.
            for (int counter = 0; counter < tempArray.Length; counter++)
            {
                string[] subs = tempArray[counter].Split(' ');

                MessageBox.Show(subs[1]);

            }

这解决了它;)我仅使用消息框进行调试,这样它就不会向服务器发送错误的信息;)

感谢 Trevor 为我指明了正确的方向!

            // Create a string array and store the contents of the Lines property.
            string[] tempArray = textBox1.Lines;
            // Loop through the array and send the contents of the array to debug window.
            for (int counter = 0; counter < tempArray.Length; counter++)
            {
                string[] subs = tempArray[counter].Split(' ');

                MessageBox.Show(subs[1]);

            }

That solved it ;) i used a messagebox only to debug, so that it did not send the wrong information to the server ;)

Thanks Trevor for pointing me in the correct direction!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文