|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Senior Member
Iscritto dal: Aug 2000
Messaggi: 1209
|
[VB.NET] Esplodere una stringa ...
1) Invio la Stringa per la Query a PHP, e fin qui' tutto OK!
2) Mi ritorna uno Stream di dati e cioe' un elenco di nomi di "Agenti" (vedi codice...) 3) Dovrei potere esplodere questa stringa di ritorno in tante sottostringhe contenenti un nome ciascuna, per poi popolarci la mia ListView se fossi in PHP "esploderei la stringa dato un carattere da decidere", in un Array di dati, per poi fare un ciclo "foreach" Popolando la "ListView". ma in VB.NET non so come si fa per esplodere una stringa ......... Codice:
Dim lipa As IPHostEntry = Dns.Resolve("localhost") Dim addr As IPAddress() = lipa.AddressList Dim lep As New IPEndPoint(lipa.AddressList(0), 80) Dim s As New Socket(lep.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp) Try s.Connect(lep) Catch e As Exception MsgBox(("Exception Thrown: " + e.ToString())) End Try Dim br As String = vbCrLf Dim protocol As String = "HTTP/1.0" Dim target As String = "/phpinfo.php" Dim body As String = "sql=SELECT Nome_Agente FROM Agenti" Dim headers As String = "POST " & target & " " & protocol & br headers += "Content-Type: application/x-www-form-urlencoded" & br headers += "Content-Length: " & body.Length.ToString & br & br Dim msg As Byte() = Encoding.ASCII.GetBytes(headers & body) Dim i As Integer = s.Send(msg, 0, msg.Length, SocketFlags.None) Dim RecvBytes(1024) As Byte Dim strRetPage As String = Nothing Dim ASCII As Encoding = Encoding.ASCII Dim bytes As Int32 = s.Receive(RecvBytes, RecvBytes.Length, 0) 'OUTPUT MsgBox(Encoding.ASCII.GetString(RecvBytes)) s.Shutdown(SocketShutdown.Both) s.Close() |
![]() |
![]() |
![]() |
#2 |
Senior Member
Iscritto dal: Apr 2004
Città: Lariano (RM)
Messaggi: 1372
|
Non serviva fare un thread nuovo, bastava l'altro!
![]() Comunque, da cosa sono divisi questi nomi di agenti nella stringa? Fai una piccola routine (Do While... per esempio) che ti separa le stringhe finchè trova il carattere di separazione, e le spara in un array.
__________________
Careful With That Axe |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 12:18.