Edmondo De Amicis posta@tiscali.it xyzabc
Edmondo Amicis posta@tiscali.it xyzabc
Stefano Carlo Nicola De Amicis posta@tiscali.it xyzabc
:quote:

A parte il fatto che questa serializzazione è un poco discutibile, il codice di sotto parte dal presupposto che i campi siano:

1° il nome (uno solo)
2° opzionale cognome, semplice o composto
3° penultimo campo, indirizzo
4° ultimo campo, password

codice:
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    Protected Sub LinkButton_separa_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            Dim s As String = Me.TextBox_stringa.Text
            Dim a As String() = s.Split(New Char() {" "c}, StringSplitOptions.RemoveEmptyEntries)
            
            If a.Length < 3 Then Throw New Exception("Errore: la stringa deve avere Nome, Cognome, Indirizzo, Password (cognome opzionale)")

            Me.Label_nome.Text = a(0)
            Me.Label_password.Text = a(a.Length - 1)
            Me.Label_indirizzo.Text = a(a.Length - 2)
            Me.Label_cognome.Text = cognome(a)
            
        Catch ex As Exception
            Me.Label_errore.Text = Server.HtmlEncode(ex.Message).Replace(vbNewLine, "
")
        End Try
        
    End Sub
    

    Private Function cognome(ByVal a As String()) As String
        Dim s As String = ""
        If a.Length = 3 Then Return s
        
        For i As Integer = 1 To a.Length - 3
            s &= " " & a(i)
        Next
        s = s.Substring(1)
        Return s
    End Function
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
        body { font-family: Verdana;}
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <asp:Label ID="Label1" runat="server" AssociatedControlID="TextBox_stringa" Font-Bold="True" Text="Stringa da separare: "></asp:Label>
        <asp:TextBox ID="TextBox_stringa" runat="server" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" Width="329px">Edmondo De Amicis posta@tiscali.it xyzabc</asp:TextBox>
        <asp:LinkButton ID="LinkButton_separa" runat="server" OnClick="LinkButton_separa_Click">Separa</asp:LinkButton>
        

        

        <table>
            <tr>
                <td>Nome:</td>
                <td><asp:Label ID="Label_nome" runat="server" Text="" EnableViewState="false"></asp:Label></td>
            </tr>
            <tr>
                <td>Cognome:</td>
                <td><asp:Label ID="Label_cognome" runat="server" Text="" EnableViewState="false"></asp:Label></td>
            </tr>
            <tr>
                <td>Indirizzo:</td>
                <td><asp:Label ID="Label_indirizzo" runat="server" Text="" EnableViewState="false"></asp:Label></td>
            </tr>
            <tr>
                <td>Password:</td>
                <td><asp:Label ID="Label_password" runat="server" Text="" EnableViewState="false"></asp:Label></td>
            </tr>
        </table>
        <asp:Label ID="Label_errore" runat="server" EnableViewState="False" Font-Bold="True" ForeColor="Red"></asp:Label>
    </form>
</body>
</html>