Click here to Skip to main content
15,886,052 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

VB
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
Posted
Updated 22-Nov-11 18:14pm
v2

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:
VB
replace(VARIABLENAME, "IP Address: ", "")


Edit: Here is an example
VB
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: ", "")
 
Share this answer
 
v3
Comments
SIFNOk 23-Nov-11 0:20am    
Thanks for the reply..i dont understand how that could work :S
LanFanNinja 23-Nov-11 0:25am    
Recheck the solution
LanFanNinja 23-Nov-11 0:25am    
+5 I added an example to your solution I hope you don't mind.
_Damian S_ 23-Nov-11 1:27am    
No, it's alright... I usually give enough information to let the other person have a crack at it themselves rather than a full solution...
SIFNOk 23-Nov-11 0:32am    
Thanks both for your contribution!! I appreciate your replys and help! it has helped me incredibly! doo u have any links for more information on string splitin..or is google the best bet....but thanks again.
Use Split method for this
C#
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
C#
al[0].ToString().Replace("IP Address: ", "").ToString();
al[1].ToString().Replace("Host:", "").ToString();
al[2].ToString().Replace("Time:", "").ToString();

Hope now it works
 
Share this answer
 
v2
Comments
SIFNOk 23-Nov-11 0:27am    
Hi Umu

Thanks for the reply...i have converted the code from C# to vb.net, but when i try make the array dispay in the textbox...it still shows "IP Address: 10.21.4.1" ect....it seems to split fine but how can i update the array after i did the replace
LanFanNinja 23-Nov-11 0:29am    
Recheck solution 1
uspatel 23-Nov-11 0:34am    
Check updated answer
LanFanNinja 23-Nov-11 0:44am    
+5
However for this particular string this code
ArrayList al = new ArrayList();
foreach (string s in split)
{
if (s.Trim() != "")
al.Add(s);
}
is not necessary. Just do this i.e.
txtip.Text = Replace(split(0).Trim(), "IP Address: ", ""))
uspatel 23-Nov-11 0:51am    
thanks.......

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900