Click here to Skip to main content
15,667,847 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi good day! i would like to ask how to split this serial
string = 12,100
continuous because it was from serial
i would like to ask how to split it like this
x= 12,10,13
y= 100,250,240

What I have tried:

i tried this one
If (split.Count = 10) Then
but the problem with there it was limit by 10 there is no specific size or lines when i will stop it will just stop when it receive ("D") sorry for my English
Updated 27-Mar-18 1:00am
Richard MacCutchan 7-Mar-18 4:54am    
What are the actual characters you receive, i.e. is there a CR/LF after each set, or are they fixed size?
Redd 7-Mar-18 7:50am    
They are not fixed size sir it was from sensor each data was sent to my textbox and they are integer sir :)
Richard MacCutchan 7-Mar-18 8:05am    
In your question you state that the data is a serial string; so which is it? And how exactly are you supposed to split the numbers?
Redd 7-Mar-18 8:22am    
this is my sample I'm so sorry i'm really terrible on explaining hehe give me more patience
Dim value As String = "500,12,600,23,400,13.........."
x = textbox1
y = textbox2
this my problem i want to split it like this one
textbox1 = 12,23,13
textbox2 = 500,600,400
thank you very much sir for you reply im so sorry for how i explain :( i hope you understand my english :) thank you sir
Richard MacCutchan 7-Mar-18 9:01am    

Dim delimiter As Char = ","c
Dim substrings() As String = value.Split(delimiter)

You now just need a loop so all even items in substrings (0, 2, 4 etc) go to textbox2, and the others to textbox1.

Share this answer
Redd 7-Mar-18 7:47am    
thank you very much!
Maciej Los 27-Mar-18 6:59am    
Try this:
Dim s As String() = {"12,100", "10,250", "13,240"}
Dim result = s.Select(Function(x) x.Split(New String(){","}, StringSplitOptions.RemoveEmptyEntries)) _
		.Select(Function(z) New With { _
			.x = z(0), _
			.y = z(1)})

For Each r In result
	Console.WriteLine("x={0} | y={1}", r.x, r.y)
Share this answer

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