Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 11th, 2008, 01:13 PM
Authorized User
 
Join Date: Feb 2007
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default Splitting a text string

How would I go about splitting a text string? Example, currently I have a Time column that actually has both the time and the venue together - FOX/2 pm. ESPN/3 pm., ect. I want to split everything after the "/" and place those characters into another column. Any suggestions?

 
Old February 11th, 2008, 03:59 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Create two extra columns in your table, then create routine that does this:

Open Recordset on current table (SELECT * FROM MyTable)

rs.MoveFirst
Do Until rs.EOF
   ReDim MyArray(2)
   MyArray = Split(rs("TimeColumn"), "/")
      rs("NewTimeColumn") = MyArray(0)
      rs("ChannelColumn") = MyArray(1)
      rs.Update
rs.MoveNext
Loop

This will loop through your current table and put the values in the new columns and preserver the old column.

Did that help?

mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old February 12th, 2008, 09:47 AM
Authorized User
 
Join Date: Feb 2007
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Not sure what I was doing wrong, but I got it to work with follwing code. I put this in as a new module. Then ran a query Expr1:ParseFirstComp([Time]), Expr2:ParseSecondComp([Time]).

Function ParseFirstComp(pValue) As String

    Dim LPosition As Integer

    'Find postion of "/"
    LPosition = InStr(pValue, "/")

    'Return the portion of the string before the "/"
    If LPosition > 0 Then
        ParseFirstComp = Left(pValue, LPosition - 1)
    Else
        ParseFirstComp = ""
    End If

End Function

Function ParseSecondComp(pValue) As String

    Dim LPosition As Integer

    'Find postion of "/"
    LPosition = InStr(pValue, "/")

    'Return the portion of the string after the "/"
    If LPosition > 0 Then
        ParseSecondComp = Mid(pValue, LPosition + 1)
    Else
        ParseSecondComp = ""
    End If

End Function
 
Old February 12th, 2008, 09:55 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Typically a consistent but moving character used to split a string would use an array and Split(). Using the two functions works as well it seems even if it requires looping through the two functions each time. There's more than one way to skin a cat, I guess.



mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old February 14th, 2008, 05:45 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

You could also try it with the LEFT, RIGHT, MID, and INSTR functions.

strVenue = Left(strInput, Instr(strInput, "/") - 1)
strStart = Mid(strInput, Instr(strInput, "/") + 1)

Of course, this treats the start time as a string and not a real date/time. You could convert that.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division





Similar Threads
Thread Thread Starter Forum Replies Last Post
Text String to XML testsubject Visual Studio 2005 1 November 27th, 2006 06:26 AM
evc++: splitting string into array using strtok bluebeta Visual C++ 2 May 3rd, 2006 01:49 AM
Splitting of string lily611 SQL Server 2000 3 March 19th, 2005 08:17 AM
string splitting qwjunk Classic ASP Basics 5 February 2nd, 2004 05:59 AM
splitting this string menesesg Classic ASP Basics 1 September 10th, 2003 12:40 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.