Search code examples
sqlsql-servervb.netreporting-servicesssrs-2008

Splitting a string in SSRS 2008 R2 using a custom code for three columns


I'm splitting the string to break up a column that separated by | . I want to split it into 3 columns.

ATTN: Brian Adams | 343 Albert Ave | 17th Street

This is the code I have now

   Public Function GetAddress1 (ByVal a as String)
        Dim b() as string
        b=Split(a,"|")
        Dim str_1(b.Length) As String
        Dim i As Integer
        For i = 1 To b.Length - 1
            str_1(i) = b(i).Split("|")(0)
        Next
   return str_1
End Function


Public Function GetAddress2 (ByVal a as String)
        Dim b() as string
        b=Split(a,"|")
        Dim str_1(b.Length) As String
        Dim i As Integer
        For i = 2 To b.Length - 1
            str_1(i) = b(i).Split("|")(0)
        Next
   return str_1
End Function

Public Function GetAttention (ByVal a as String)
        Dim b() as string
        b=Split(a,"|")
        Dim str_1(b.Length) As String
        Dim i As Integer
        For i = 0 To b.Length - 2
            str_1(i) = b(i).Split("|")(0)
        Next
   return str_1

End Function

The functions work when there's only 2 values ATTN: Brian Adams | 343 Albert Ave but when there's three values the GetAddress1 will grab info to the right of the the second | and get the GetAddress2 value.


Solution

  • Public Function GetAddress1 (ByVal a as String)
            Dim b() as string
            b=Split(a,"|",2)
            Dim str_1(b.Length) As String
            Dim i As Integer
            For i = 1 To b.length - 1 
                str_1(i) = b(i).Split("|")(0)
            Next
       return str_1
    End Function
    

    Writing the ,2 located the second value in the string without throwing an error.