我的原文件如下:
中国,hello,山东,shandong
中国海,hello,山东省,shandong
中国海洋,hello,山东省会,shandong我期待的结果是:
中国      hello  山东      shandong
中国海    hello  山东省    shandong
中国海洋  hello  山东省会  shandong
格式为a(10) a(7) a(10) a(8)请各位大虾帮帮忙,最好有代码,跪谢!

解决方案 »

  1.   

    可以使用split函数分割成单词。
      

  2.   

    然后调用Format函数格式化分割后的单词。
      

  3.   

    Option ExplicitPrivate Sub Form_Load()
    Debug.Print GetGs("中国 , hello, 山东, shandong")
    Debug.Print GetGs("中国海 , hello, 山东省, shandong")
    Debug.Print GetGs("中国海洋 , hello, 山东省会, shandong")
    End Sub
    Private Function GetGs(a As String) As String
    Dim b() As String
    Dim c As String
    b = Split(a, ",")
    b(0) = Trim(b(0))
    c = c & b(0) & String(10 - LenB(StrConv(b(0), vbFromUnicode)), " ")
    b(1) = Trim(b(1))
    c = c & b(1) & String(7 - LenB(StrConv(b(1), vbFromUnicode)), " ")
    b(2) = Trim(b(2))
    c = c & b(2) & String(10 - LenB(StrConv(b(2), vbFromUnicode)), " ")
    b(3) = Trim(b(3))
    c = c & b(3) & String(8 - LenB(StrConv(b(3), vbFromUnicode)), " ")
    GetGs = c
    End Function
      

  4.   

    我自己的方法是先定义一个空格字符串
    strTemp=space(35)
    然后用分割后的单词去填充它所在的位置,字母当然没有什么问题,可是遇到汉字的时候,填充进去的时候只占一个空格,但是写出来时位置便错行。
    假设已将原文的字符取出付给一个字符数组strArr(4)
    mid(strTemp,1,10)=strArr(0) & space(10-len(strArr(0)))
    mid(strTemp,11,7)=strArr(1) & space(7-len(strArr(1)))
    mid(strTemp,18,10)=strArr(2) & space(10-len(strArr(2)))
    mid(strTemp,28,8)=strArr(3) & space(8-len(strArr(3)))
    写出的结果如下:
    中国        hello  山东        shandong
    中国海       hello  山东省       shandong
    中国海洋      hello  山东省会      shandong
    烦请各位大虾帮助解决。
      

  5.   

    private type myRecord
       str1 as string *10
       str2 as string * 7
       str3 as string * 10
       str 4 as string * 8
    end type  Dim xx As myRecord
      Dim strArr
      strArr = Array("中国", "hello", "山东", "shandong")
      xx.str1 = strArr(0)
      xx.str2 = strArr(1)
      xx.str3 = strArr(2)
      xx.str4 = strArr(3)
      
        Dim byt() As Byte
        With Picture1
            Open "d:\1.txt" For Random Access Write As #1
            Put #1, , xx
            Close #1
        End With
      

  6.   

    Function getit(ByVal x As String) As String
    Dim temp() As String
    temp = Split(x, ",")
    For i = 0 To UBound(temp)
    temp(i) = Trim(temp(i)) & StrConv(Space(Choose(i + 1, 5, 7, 5, 8) - Len(Trim(temp(i)))), vbUnicode)
    Next
    getit = Join(temp, "")
    getit = getit & " ,length=" & Len(getit)
    End Function
    Private Sub Command1_Click()
    Debug.Print getit("中国 , hello, 山东, shandong")
    Debug.Print getit("中国海 , hello, 山东省, shandong")
    Debug.Print getit("中国海洋 , hello, 山东省会, shandong")End Sub
      

  7.   

    sub FormatString(TXT1 as string,TXT2 as string,TXT3 as string)
    dim Str,Str1,Str2
    dim I as long
    dim L as long
    str=split(TXT1,",",-1)
    str1=split(TXT2,",",-1)
    str2=split(TXT3,",",-1)
    for i=lbound(str) to ubound(str)
       if Len(str(I))>L then L=Len(str(I))
       if Len(str1(I))>L then L=Len(str1(I))
       if Len(str2(I))>L then L=Len(str2(I))
    next
    for i=lbound(str) to ubound(str)
       TXT1=TXT1 & str(I) & space(L-len(str(I)))
       TXT2=TXT2 & str1(I) & space(L-len(str1(I)))
       TXT3=TXT3 & str2(I) & space(L-len(str2(I)))
    next
    end sub
    试试这个吧