Dim i As Long Dim chn As String = "GRENIER Alain" chn = chn.Trim ' enlève les espaces au début et à la fin Dim resultat As String = String.Empty ' chaine vide resultat = chn.Substring(0, 1) For i = 1 To chn.Length - 1 If chn.Substring(i, 1) " " Then resultat resultat + chn.Substring(i + 1, 1) Next i Label1.Text = resultat
Dim i As Long Dim chn As String = TextBox1.Text.ToString chn = chn.Trim ' enlève les espaces au début et à la fin Dim resultat As String = chn.Substring(0, 1) ' première lettre du premier mot For i = 1 To chn.Length - 2 ' on cherche les espaces ' si le caractère courant est un espace et que le caractère suivant n'est pas un espace ' on ajoute la première lettre de ce mot If chn.Substring(i, 1) " " and chn.Substring(i+1,1) <> " " Then resultat resultat + chn.Substring(i + 1, 1) Next i Label1.Text = resultat
Dim str as string = "bonjour tous" if (str.Contains(" ")) then dim tab as string() = .Split(" ") dim result as List(of String)= new List(Of String) foreach t as string in tab result = a.Add(t(0)) next return result.Join("") else ' substring() end if
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionDim i As Long Dim chn As String = TextBox1.Text.ToString If (chn.Contains(" ")) Then chn = chn.Trim ' enlève les espaces au début et à la fin Dim resultat As String = String.Empty ' chaine vide resultat = chn.Substring(0, 1) For i = 1 To chn.Length - 1 If chn.Substring(i, 1) " " Then resultat resultat + chn.Substring(i + 1, 1) Next i Label1.Text = resultat Else Label1.Text = chn.Substring(0, 2) End If
Dim i As Long Dim chn As String = TextBox1.Text.ToString chn = chn.Trim ' enlève les espaces au début et à la fin Dim resultat As String = chn.Substring(0, 1) ' première lettre du premier mot For i = 1 To chn.Length - 1 ' on cherche les espaces ' si le caractère courant est un espace et que le caractère précédent n'est pas un espace ' on ajoute la première lettre de ce mot If chn.Substring(i, 1) " " and chn.Substring(i-1,1) <> " " Then resultat resultat + chn.Substring(i + 1, 1) Next i Label1.Text = resultat
"bonjour à tous".Split(" ")