Click here to Skip to main content
15,881,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello. As I have a problem. I want to separate the data, such as in the following example. Thank you in advance.


note: ^^^X^A1.....^B1.....^C1.....^D1....^E1....^A2....^B2...^C2....^D2....^E2...^^^_X
....( Any data can be)


sample string= ^^^X^A12505361170^B1255907002^C1ABCD^D12555^E12014/10/10 23:10:02^^^_X

Textbox1.text=2505361170

textbox2.text=255907002

textbox3.text=ABCD

textbox4.text=2555

textbox5.text=2014/10/10 23:10:02
Posted
Comments
[no name] 11-Oct-14 7:42am    
So split it and parse out the data, or write a regular expression.
CHill60 11-Oct-14 7:50am    
Are you saying that any character following a ^ should be ignored - that they are some kind of marker?

1 solution

There are several ways you could do this.

Regular Expressions are one way, but I think it might be a bit too complex for this scenario.

You could use "brute force" parsing ... i.e. read the string one character at a time, ignoring ^ and anything immediately afterwards, building up another string until you hit another ^. But that is very clunky.

Or you could use the built-in VB.NET method Split()[^]

Something similar to this would work:
VB
Dim sample As String = "^^^X^A12505361170^B1255907002^C1ABCD^D12555^E12014/10/10 23:10:02^^^_X"

Dim splitSample As String() = Split(sample, "^", -1, StringSplitOptions.RemoveEmptyEntries)

For Each token As String In splitSample
    If token.Length > 1 Then
        Debug.Print(token.Substring(2)) 'this is where you assign to your text boxes
    End If
Next
 
Share this answer
 
Comments
EssenceGold 11-Oct-14 9:27am    
Yes working. Thank you very much.

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