CodeItBetter Programming Another VB Programming Blog

First Name, Last Name swaping in a string – Example

Posted on January 5, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
'String Manipulation - First Name, Last Name swaping in a string - Example
Public Function StringManipulation(ByVal strFileName As String) As String
    Dim strTemp() As String
    Dim strFinal As String
    Dim intCount As Integer
    Dim intLastWordPos As Integer
    Dim intLastWordLength As Integer
    Dim strLastWord As String
 
    Debug.Print strFileName
    strFileName = Replace(strFileName, ".zip", "")
    strTemp = Split(strFileName)
 
    For intCount = LBound(strTemp) To UBound(strTemp)
        If Right$(strFinal, 1) = "," Then
            intLastWordPos = InStrRev(strFinal, " ")
            intLastWordLength = Len(strFinal) - intLastWordPos
            strLastWord = Mid$(strFinal, intLastWordPos + 1, intLastWordLength - 1)
            strFinal = Left$(strFinal, intLastWordPos)
            strFinal = Trim$(strFinal & strTemp(intCount)) & " " & strLastWord
        Else
            strFinal = Trim$(strFinal & " " & strTemp(intCount))
        End If
    Next intCount
    strFinal = strFinal & ".zip"
    StringManipulation = strFinal
    Debug.Print strFinal
End Function
'How can I call this function:
'MsgBox StringManipulation("ka1000-10 - killers, the - song, the.zip")
'MsgBox StringManipulation("ka1000-10 - bon jovi & killers, the - song, the.zip")
'MsgBox StringManipulation("ka1000-10 - jovi, bon & killers, the - song, the.zip")
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.