We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,259 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Help with Array (splitting)

Hi,

I am trying to split a single line of data into three separate parts so that they can be displayed in different textboxes. The data looks like this:

item1_item2_item3

The code that I tried is:

Dim arrayLines() As String
Dim record As String

record = Subs.Text
arrayLines = record.Split("_")

TextBox1.Text = arrayLines(0)
TextBox2.Text = arrayLines(1)

I don't seem to have much luck, I don't even get an error message when I click on the button. Any suggestions..?

2
Contributors
2
Replies
22 Minutes
Discussion Span
1 Year Ago
Last Updated
3
Views
Question
Answered
collin_ola
Junior Poster in Training
55 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

hello !
please use this code this will solve your prob :)

Dim str As String
        Dim strArr() As String
        Dim count As Integer
        str = txtUsername.Text ' txtbox having txt you wana split.
        strArr = str.Split("_")
        For count = 0 To strArr.Length - 1
            If txt1.Text = "" Then
                txt1.Text = strArr(count).ToString

            Else
                If txt2.Text = "" Then
                    txt2.Text = strArr(count).ToString
                Else
                    If txt3.Text = "" Then
                        txt3.Text = strArr(count).ToString
                    End If
                End If
            End If

        Next

if your prob is solved then pleas mark this thread solved and also dont forget to add reputation .

Regards

M.Waqas Aslam
Master Poster
747 posts since Aug 2011
Reputation Points: 50
Solved Threads: 121
Skill Endorsements: 2

As always, worked perfectly!! Thanks!

collin_ola
Junior Poster in Training
55 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 1 Year Ago by M.Waqas Aslam

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0594 seconds using 2.66MB