文本框值转换为字符串数组或其他内容 [英] textbox value into string array or something

查看:76
本文介绍了文本框值转换为字符串数组或其他内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

我的vb.net技能非常有限,我在.net 4 Framework中使用vb.net.我想知道是否有人可以提供帮助.我已经在Google上搜索了找到的mimial结果,但不确定是否要针对我想要实现的功能使用正确的终端设备...
但基本上我有一个带有4个文本框的表单(txtinfo,txtip,txthost,txttime),当表单加载时,它会将文本文件加载到TXTINFO. (请参见下文)

 IP地址:10.21.4.1,主机:RTR-BIF01,时间:格林尼治标准时间18:00 




我的问题是从这个字符串中我希望能够提取必要的信息以显示在其他文本框中,所以我想删除标题名称-IP,主机,时间...示例

 txtip.text = " 
txthost.text = " 
txttime.text = today.toshorttime.tostring 



任何信息都将是有用的,或者帮助将是巨大的...再次,我对vb的技能设置非常有限..

在此先感谢

亲切的问候

解决方案

这很容易实现.在逗号处分割字符串,然后删除文本的IP地址:主机:和时间:部分,将剩下的部分保存到文本框中.

删除它们的一种方法是这样的:

 replace(VARIABLENAME," " )



这是一个例子

  Dim  infoString  As   String  = " 
 Dim 拆分 As   String ()= infoString .Split("  c)
txtip.Text = Replace(split( 0 ).Trim()," " )
txthost.Text = Replace(split( 1 ).Trim()," " )
txttime.Text = Replace(split( 2 ).Trim(),"  ")


为此使用分割方法

 字符串 ss = " 字符串 [] split = ss.Split( Char [] {,'});

           ArrayList al =  ArrayList();

            foreach (字符串 s  in 中的拆分)
           {

               如果(s.Trim()!= " )
                   al.Add(s);
           }


并将值分配给文本框为

 al [ 0 ].ToString().Replace("  IP地址:" ").ToString ();
al [ 1 ].ToString().Replace("  ").ToString();
al [ 2 ].ToString().Replace("  ").ToString(); 


希望现在可以正常工作


Hi Everyone.

I am very limited on my vb.net skills, i am using vb.net in .net 4 Framework. I was wondering if someone could assist. i have searched google finding mimial result, im not sure if i am using the correct terminalogy for what i want to achieve...
but basicallyI have a form with a 4 textboxs(txtinfo, txtip, txthost, txttime) When the form loads it loads a textfile to TXTINFO. (please see below)

IP Address: 10.21.4.1, Host: RTR-BIF01,Time: 18:00 GMT




My issue is from this string i want to be able to pull out the nessary info to display in the other textboxs, soo i want to remove the Header names - IP, Host, time...example

txtip.text = "10.21.4.1"
txthost.text = "RTR-BIF01"
txttime.text = today.toshorttime.tostring



Any information would be great or help would be great...once again my skill set for vb is very limited..

Thanks in advance

kind regards

解决方案

This is fairly simple to achieve. Split the string at the comma, then remove the IP Address: Host: and Time: portions of the text, saving what''s left into your text boxes.

One option to remove them is like this:

replace(VARIABLENAME, "IP Address: ", "")



Edit: Here is an example

Dim infoString As String = "IP Address: 10.21.4.1, Host: RTR-BIF01,Time: 18:00 GMT"
Dim split As String() = infoString.Split(","c)
txtip.Text = Replace(split(0).Trim(), "IP Address: ", "")
txthost.Text = Replace(split(1).Trim(), "Host: ", "")
txttime.Text = Replace(split(2).Trim(), "Time: ", "")


Use Split method for this

string ss = "IP Address: 10.21.4.1, Host: RTR-BIF01,Time: 18:00 GMT";
           string[] split = ss.Split(new Char[] { ',' });

           ArrayList al = new ArrayList();

           foreach (string s in split)
           {

               if (s.Trim() != "")
                   al.Add(s);
           }


and assign value to text boxes as

al[0].ToString().Replace("IP Address: ", "").ToString();
al[1].ToString().Replace("Host:", "").ToString();
al[2].ToString().Replace("Time:", "").ToString();


Hope now it works


这篇关于文本框值转换为字符串数组或其他内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆