[AccessD] A2003 - Build a List/Array from Tokens in a blurb
Bill Benson
bensonforums at gmail.com
Thu Sep 3 08:12:10 CDT 2015
Split is my friend? Is that why all my friends split?
On Fri, Aug 21, 2015 at 4:52 AM, Gustav Brock <gustav at cactus.dk> wrote:
> Hi Darren
>
> Split is your friend:
>
> <code>
> Public Function SplitTokens(ByVal Message As String) As String()
>
> Dim Parts As Variant
> Dim Tokens() As String
> Dim Token As Integer
>
> ' Split into first parts.
> Parts = Split(Message, "[")
>
> If UBound(Parts) <= 0 Then
> ' Return array with LBound = 0.
> ReDim Tokens(0)
> Else
> ' Return array with LBound = 1.
> ' Clean parts and fill array.
> ReDim Tokens(1 To UBound(Parts))
> For Token = 1 + LBound(Parts) To UBound(Parts)
> Tokens(Token) = "[" & Split(Parts(Token), "]", 2)(0) & "]"
> Next
>
> ' Split into second parts.
> Parts = Split(Message, "{")
>
> If UBound(Parts) > 0 Then
> ' Clean parts and append to array.
> ReDim Preserve Tokens(1 To UBound(Tokens) + UBound(Parts))
> For Token = 1 + LBound(Parts) To UBound(Parts)
> Tokens(UBound(Tokens) - 1 + Token) = "{" &
> Split(Parts(Token), "}", 2)(0) & "}"
> Next
> End If
> ' Return array with LBound = 1.
> End If
>
> SplitTokens = Tokens
>
> End Function
> </code>
>
> /gustav
>
> -----Oprindelig meddelelse-----
> Fra: AccessD [mailto:accessd-bounces at databaseadvisors.com] På vegne af
> Darren - Active Billing
> Sendt: 21. august 2015 02:35
> Til: Access Developers discussion and problem solving <
> accessd at databaseadvisors.com>
> Emne: [AccessD] A2003 - Build a List/Array from Tokens in a blurb
>
> Hi Team
>
> if I had a field with the following blurb...
>
> Dear [FirstName],
> Today is [NameOfDay] and the date is the [DateOfMonth] of [NameOfMonth].
> Kind Regards,
> {SignatoryName}
>
> I can see in that blurb there are 5 tokens surrounded by Square and or
> Curley brackets.
> How could I run though that text and build a list of the 5 tokens such
> that I can produce a list/array like...
>
> [FirstName]
> [NameOfDay]
> [DateOfMonth]
> [NameOfMonth]
> {SignatoryName}
>
> Many thanks in advance.
>
> Darren
>
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>
More information about the AccessD
mailing list