Selecting Specific Text from a string

Hi Experts

I know this sounds very stupid and I did this when I still had my programming booths on!! However I need help please.

I have a string like this
23/03/07 11:25AM  7242 56

First note that there is two space between the time and the number 7242.

Now what I need to do is copy each section like date time the number 7242 and 56 to its own string to be put into it's own db field.

How can a specify to start copying in one position and stop at another then copy that text to another string so that I have the following at the end of the day:

txtDate = 23/03/07
txtTime = 11:25AM
txtExt = 7242
txtTrunk = 56

Thanks
aliencoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

aliencoAuthor Commented:
One more thing I need this for VB6 but also for 2005
0
PaulHewsCommented:
Dim strText As String
Dim strSplit() As String
strText = "23/03/07 11:25AM  7242 56"
strSplit = Split(strText, " ")

txtDate.Text = strSplit(0)
txtTime.Text = strSplit(1)
txtExt.Text = strSplit(3)
txtTrunk.Text = strSplit(4)
0
PaulHewsCommented:
VS2005


Dim strText As String = "23/03/07 11:25AM  7242 56"
Dim TextArr() As String = strText.Split(" "c)

txtDate.Text = TextArr(0)
txtTime.Text = TextArr(1)
txtExt.Text = TextArr(3)
txtTrunk.Text = TextArr(4)
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

aliencoAuthor Commented:
Okay that seems to work half way thanks.

Next question, below is the full string with 2 variants:

23/03/07 11:25AM  7242 56 <I>0824786472             0'00 00:07'25
23/03/07 11:25AM *7410 60 0836271465                     00:00'16  

I need to do the same with *7410 as with 7242 however there will now only be one space between the time and *7410

Also how will I handle the <1> it needs to go to it own field and offcourde the long space between the number and durations?
0
PaulHewsCommented:
If the only difference is the number of spaces between fields, you can normalize them with a replace:

2005:

        Do While strText.Contains("  ") 'double space
            strText = strText.Replace("  ", " ") 'replace double space with single space...
        Loop
        Dim TextArr() As String = strText.Split(" "c)

VB6:

Do While InStr(strText, "  ") > 0
    strText = Replace(strText, "  ", " ")
Loop
strSplit = Split(strText, " ")

Now your arrays will be normalized, only containing the non-blank values.  
0
PaulHewsCommented:
>Also how will I handle the <1> it needs to go to it own field and offcourde the long space between the number and durations?

You need to decide exactly what the full format is, and what the possibilities are, and then decide a method of parsing.  Obviously the example you gave initially is quite different than the requirements you are posting now.  Where does <1> come from, what does it mean, what other values can be expected, etc.

0
aliencoAuthor Commented:
It can only be the <1> it indicates a incoming call to a pbx system if it is not there is indicates a outgoing call.
0
PaulHewsCommented:
In the post at http:#a20761755 the first line has 7 fields and the second line has 6 fields...   Is there supposed to be a space in 0'00 00:07'25  ?    

0
aliencoAuthor Commented:
Yes there need to be as 0'00 is the ring time and only on incomming calls where 00:07'25 is the actual call time ring time is just seconds where call time can be upo to hours
0
PaulHewsCommented:
So when there's a <I>, there will be 7 fields + the incoming indicator...?  Otherwise 6 fields?
0
aliencoAuthor Commented:
Correct
0
PaulHewsCommented:
VB6 something like this:
Option Explicit
 
Private Sub Command1_Click()
   
                           
    Dim strSplit() As String
    Dim strText As String
    Dim i As Integer, j As Integer
    Dim bIsIncoming As Boolean
   

    strText = "23/03/07 11:25AM  7242 56 <I>0824786472             0'00 00:07'25"
    Do While InStr(strText, "  ") > 0
        strText = Replace(strText, "  ", " ")
    Loop
   
    bIsIncoming = False
    If InStr(strText, "<I>") > 0 Then
        bIsIncoming = True
        strText = Replace(strText, "<I>", "")
    End If
    strSplit = Split(strText, " ")
   
    Text1.Text = strSplit(0)
    Text2.Text = strSplit(1)
    Text3.Text = strSplit(2)
    Text4.Text = strSplit(3)
    Text5.Text = strSplit(4)
    Text6.Text = strSplit(5)
   
   
    If bIsIncoming Then
        Text7.Text = strSplit(6)
        Text8.Text = "Is Incoming"
    Else
        Text7.Text = ""
        Text8.Text = "Is not incoming"
    End If

End Sub


VB2005, something like this:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim strText As String = "23/03/07 11:25AM  7242 56 <I>0824786472             0'00 00:07'25"
        Do While strText.Contains("  ") 'double space
            strText = strText.Replace("  ", " ") 'replace double space with single space...
        Loop
        Dim TextArr() As String = strText.Split(" "c)

        Dim bIsIncoming As Boolean = False
        If InStr(strText, "<I>") > 0 Then
            bIsIncoming = True
            strText = Replace(strText, "<I>", "")
        End If


        TextBox1.Text = TextArr(0)
        TextBox2.Text = TextArr(1)
        TextBox3.Text = TextArr(2)
        TextBox4.Text = TextArr(3)
        TextBox5.Text = TextArr(4)
        TextBox6.Text = TextArr(5)


        If bIsIncoming Then
            TextBox7.Text = TextArr(6)
            TextBox8.Text = "Is incoming"
        Else
            TextBox7.Text = String.Empty
            TextBox8.Text = "Not incoming"
        End If

    End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.