Link to home
Start Free TrialLog in
Avatar of alienco
alienco

asked on

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
Avatar of alienco
alienco

ASKER

One more thing I need this for VB6 but also for 2005
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)
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)
Avatar of alienco

ASKER

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?
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.  
>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.

Avatar of alienco

ASKER

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.
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  ?    

Avatar of alienco

ASKER

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
So when there's a <I>, there will be 7 fields + the incoming indicator...?  Otherwise 6 fields?
Avatar of alienco

ASKER

Correct
ASKER CERTIFIED SOLUTION
Avatar of PaulHews
PaulHews
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial