求一函数funChangeStr("1234,4567,789",3,1)  返回"789,1234,4567"
请问如何写?

解决方案 »

  1.   

    function funChangeStr(str as string,n as integer,m as integer) 
    c=split(str,",")
    funchangestr=c(2) & "," & c(0) & "," & c(1)
    end function
      

  2.   

    funtion funChangeStr(SrcStr as string,pos1 as long,pos2 as long) as string
        dim a() as string,s as string
        a=split(srcstr,",")
    if pos1<=ubound(a)+1 and pos2<=ubound(a)+1 then
        s=a(pos2-1)
        a(pos2-1)=a(pos1-1)
        a(pos1-1)=s
        funChangeStr=join(a,",")
    else
        funChangeStr=SrcStr
    end if
    end function
      

  3.   

    '楼主的意思是将第3个放到第1的位置上吧.Private Sub Command1_Click()
    MsgBox funChangeStr("1234,4567,789", 3, 1) ' 返回"789,1234,4567"
    End Sub
    Private Function funChangeStr(strTemp As String, a As Integer, b As Integer) As String
    Dim ls_Content() As String
    Dim tempA As String, tempB As String
    Dim I As Longls_Content = Split(strTemp, ",")tempA = ls_Content(a - 1)
    ls_Content(a - 1) = ""For I = 0 To UBound(ls_Content)
        If I = b - 1 Then funChangeStr = funChangeStr & tempA & ","
        If ls_Content(I) <> "" Then funChangeStr = funChangeStr & ls_Content(I) & ","
    Next I
    funChangeStr = Mid(funChangeStr, 1, Len(funChangeStr) - 1)
    End Function
      

  4.   

    Public Function FunChangeStr(a1 As String, a2 As Integer, a3 As Integer) As String
        Dim Ddd
        Dim i As Integer
        Ddd = Split(a1, ",")
        If UBound(Ddd) + 1 < a2 + a3 - 1 Then
            MsgBox "参数不正确"
            Exit Function
        Else
            For i = a2 - 1 To (a2 - 1 + a3) - 1
                FunChangeStr = FunChangeStr & Ddd(i) & ","
                Ddd(i) = ""
            Next
            For i = 0 To UBound(Ddd)
                If Ddd(i) <> "" Then
                    FunChangeStr = FunChangeStr & Ddd(i) & ","
                End If
            Next
        End If
        FunChangeStr = Mid(FunChangeStr, 1, Len(FunChangeStr) - 1)
    End Function
      

  5.   

    我也來一個:
    Private Function funChangeStr(ByVal strCharacters As String, ByVal n1 As Integer, ByVal n2 As Integer) As String
        Dim arrCharacters() As String
        Dim strTemp As String
        Dim objCollection As Collection
        Dim i As Integer
        arrCharacters = Split(strCharacters, ",")
        Set objCollection = New Collection
        For i = 0 To UBound(arrCharacters)
                objCollection.Add arrCharacters(i)
        Next    If n1 > n2 Then
            objCollection.Add objCollection.Item(n1), , n2
            objCollection.Remove n1 + 1
        Else
            objCollection.Add objCollection.Item(n1), , , n2
            objCollection.Remove n1
        End If
        For i = 0 To UBound(arrCharacters)
            arrCharacters(i) = objCollection.Item(i + 1)
        Next
        funChangeStr = Join(arrCharacters, ",")
        Set objCollection = Nothing
    End Function