Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Comment peut diviser un texte avec retour a la ligne ? the problem c'est je ne connais qu'est la method correcte car je suis débitant en visual-studio

Translation:
How can a text be split with a line break? the problem is I don't know what the correct method is because I'm selling in visual-studio


What I have tried:

Bonjour, moi je travaille avec la méthode de "split string "elle fonctionne mais je peux faire un retour a la ligne sans supprimer le variable de split

Translation:
Hello, I work with the "split string" method, it works but I can make a line break without deleting the split variable


VB.NET
Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
TextBox1.Text = "5156785123579"
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
TextBox2.Clear()

For Each word As String In Split(TextBox1.Text, "5")
TextBox2.Text = TextBox2.Text & word & vbCrLf & word
Next

End Sub


'il m'affiche

Translation:
It shows me


'1
'678123
'12379
'79


moi je recherche a l'afficher de sa facon

Translation:
I am looking to display it in his own way


'51
'5678123
'512379
'579

le 5 reste sans supprimer et faire une retour a ligne
est la méthode de split est faux si faux qu'elle la meilleur solution
merci d'avance <3

Translation:
the 5 remains without deleting and returning to line
is the split method is wrong if wrong it the best solution
thanks in advance <3
Posted
Updated 24-Apr-22 2:42am
v2
Comments
Maciej Los 24-Apr-22 8:36am    
This forum uses English. Please, use English.

1 solution

Well...

Try this:
VB.NET
TextBox2.Text = TextBox2.Text & word & vbCrLf & "5" & word


[EDIT]
Or use custom function, like this:
VB.NET
Sub Main
	Dim inputstr = "5156785123579"
	Dim splitter = "5"
	
	Dim data As List(Of String) = CustomSplit(inputStr, splitter)
	For Each s As String In data
		Console.WriteLine(s)
	Next 
	
End Sub

' Define other methods and classes here
Function CustomSplit(StringToSplit As String, SplitBy As String) As List(Of String)
	Dim retVal As List(Of String) = New List(Of String)
	Dim l  As Integer = StringToSplit.Length
	Dim currIndex As Integer = 1
	Dim prevIndex As Integer = 0
	
	Do 
		currIndex = StringToSplit.IndexOf(SplitBy, currIndex, StringComparison.InvariantCulture)
		If currIndex >-1 Then
			retVal.Add(StringToSplit.Substring(prevIndex, currIndex -prevIndex))
			previndex = currIndex 
			currIndex += 1
		Else
			currIndex = l
			retVal.Add(StringToSplit.Substring(prevIndex, currIndex - prevIndex))
		End If
	Loop While	currIndex < l
	
	Return retVal

End Function
 
Share this answer
 
v2
Comments
0x01AA 24-Apr-22 9:19am    
Mes cinq
Maciej Los 24-Apr-22 11:19am    
merci

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