我将下面的几个字符串排序,得到这个结果:
上海,北京,Beijing,China,安徽然后又用strconv将字符串转换,又得到了这个结果:
Beijing,China,北京,安徽,上海但这些都不是我想要的,我想按照字典顺序来排序:
Beijing,China,安徽,北京,上海我应该怎么做呢?

解决方案 »

  1.   

    哦?还有这事?笨办法,把这些加到一个ListBox里,然后让它帮你排:)
    Sorted设为真~
      

  2.   

    呵呵,这个年头真的曾经闪现过.整好这个project是数据库的,我曾打算开一个table,然后用SQL排序,呵但是很想知道为什么会这样
      

  3.   

    就是sql的排序就会按你的要求来排了
      

  4.   

    这么麻烦?那还是想其他办法吧大家帮我看看我的排序算法没错吧?(我已经被这事折磨得很不自信了)
    Private Sub Command1_Click()
    Dim a(5) As String, strTemp As String
    Dim i As Long, j As Long
    a(1) = "上海": a(2) = "北京": a(3) = "Beijing"
    a(4) = "China": a(5) = "安徽"
    For i = 1 To 5
        For j = i + 1 To 5
            If a(i) > a(j) Then
                strTemp = a(i): a(i) = a(j): a(j) = strTemp
            End If
        Next j
    Next i
    For i = 1 To 5
        Debug.Print a(i)
    Next i
    End Sub
      

  5.   

    Private Sub Command1_Click()
    Dim CharStr$()
    Dim UcodeStr$()
    Dim a$(6)
    Dim charCnt&, ucodeCnt&a(1) = "上海": a(2) = "北京": a(3) = "Beijing"
    a(4) = "China": a(5) = "安徽": a(6) = "人民"
    For i = 1 To 6
        If Asc(Left(a(i), 1)) > 0 Then
            charCnt = charCnt + 1
            ReDim Preserve CharStr(charCnt)
            CharStr(charCnt) = a(i)
        Else
            ucodeCnt = ucodeCnt + 1
            ReDim Preserve UcodeStr(ucodeCnt)
            UcodeStr(ucodeCnt) = a(i)
        End If
    Next
    For i = 1 To charCnt
        For j = i + 1 To charCnt
            If CharStr(i) > CharStr(j) Then
                strTemp = CharStr(i): CharStr(i) = CharStr(j): CharStr(j) = strTemp
            End If
        Next j
    Next i
    For i = 1 To ucodeCnt
        For j = i + 1 To ucodeCnt
            If UcodeStr(i) < UcodeStr(j) Then
                strTemp = UcodeStr(i): UcodeStr(i) = UcodeStr(j): UcodeStr(j) = strTemp
            End If
        Next j
    Next i
    For i = 1 To charCnt
        a(i) = CharStr(i)
    Next
    For i = 1 To ucodeCnt
        a(i + charCnt) = UcodeStr(i)
    Next
    For i = 1 To 6
        MsgBox a(i)
    Next i
    End Sub
      

  6.   

    拼音怎么计算呢?
    ====================
    转贴以前的一个帖子:CSDN - 专家门诊 -  
     
     
    主  题:  急,求解用VB自动获取汉字的首拼音
     
    作  者:  lcs810 (最怕编程)  
    信 誉 值:  94 
    所属论坛:  VB 非技术类 
    问题点数:  100 
    回复次数:  15 
    发表时间:  2003-12-12 11:32:50 
       
     
       
     
    各位大侠,小弟,急需求得一段汉字字符串的每个汉字的首拼音,但这字符串的其它符号,数字不要。
     
     回复人: yoki(小马哥) ( ) 信誉:100  2003-12-12 11:57:00  得分:0  
     
     
      Option Explicit'在窗口中加两个TEXT控件,一个输入中文,一个显示英文
    Private Sub Form_Load()
        Text1.Text = "我是中国人"
    End SubPrivate Sub Command1_Click()
        Text2.Text = GetPY(Text1.Text)
    End Sub'获得输入名称的首字拼音
    Private Function GetPY(ByVal strParmeter As String) As String
        Dim intTmp As String, i As Long
        
        For i = 1 To Len(strParmeter)
            intTmp = Asc(Mid(strParmeter, i, 1))        If intTmp < Asc("啊") Then
                GetPY = GetPY & "*"
            ElseIf intTmp >= Asc("啊") And intTmp < Asc("芭") Then
                GetPY = GetPY & "A"
            ElseIf intTmp >= Asc("芭") And intTmp < Asc("擦") Then
                GetPY = GetPY & "B"
            ElseIf intTmp >= Asc("擦") And intTmp < Asc("搭") Then
                GetPY = GetPY & "C"
            ElseIf intTmp >= Asc("搭") And intTmp < Asc("蛾") Then
                GetPY = GetPY & "D"
            ElseIf intTmp >= Asc("蛾") And intTmp < Asc("发") Then
                GetPY = GetPY & "E"
            ElseIf intTmp >= Asc("发") And intTmp < Asc("噶") Then
                GetPY = GetPY & "F"
            ElseIf intTmp >= Asc("噶") And intTmp < Asc("哈") Then
                GetPY = GetPY & "G"
            ElseIf intTmp >= Asc("哈") And intTmp < Asc("击") Then
                GetPY = GetPY & "H"
            ElseIf intTmp >= Asc("击") And intTmp < Asc("喀") Then
                GetPY = GetPY & "J"
            ElseIf intTmp >= Asc("喀") And intTmp < Asc("垃") Then
                GetPY = GetPY & "K"
            ElseIf intTmp >= Asc("垃") And intTmp < Asc("妈") Then
                GetPY = GetPY & "L"
            ElseIf intTmp >= Asc("妈") And intTmp < Asc("拿") Then
                GetPY = GetPY & "M"
            ElseIf intTmp >= Asc("拿") And intTmp < Asc("哦") Then
                GetPY = GetPY & "N"
            ElseIf intTmp >= Asc("哦") And intTmp < Asc("啪") Then
                GetPY = GetPY & "O"
            ElseIf intTmp >= Asc("啪") And intTmp < Asc("期") Then
                GetPY = GetPY & "P"
            ElseIf intTmp >= Asc("期") And intTmp < Asc("然") Then
                GetPY = GetPY & "Q"
            ElseIf intTmp >= Asc("然") And intTmp < Asc("撒") Then
                GetPY = GetPY & "R"
            ElseIf intTmp >= Asc("撒") And intTmp < Asc("塌") Then
                GetPY = GetPY & "S"
            ElseIf intTmp >= Asc("塌") And intTmp < Asc("挖") Then
                GetPY = GetPY & "T"
            ElseIf intTmp >= Asc("挖") And intTmp < Asc("昔") Then
                GetPY = GetPY & "W"
            ElseIf intTmp >= Asc("昔") And intTmp < Asc("压") Then
                GetPY = GetPY & "X"
            ElseIf intTmp >= Asc("压") And intTmp < Asc("匝") Then
                GetPY = GetPY & "Y"
            ElseIf intTmp >= Asc("匝") And intTmp < 0 Then
                GetPY = GetPY & "Z"
            ElseIf (intTmp >= 65 And intTmp <= 91) Or (intTmp >= 97 And intTmp <= 123) Then
                GetPY = GetPY & Mid(strParmeter, i, 1)
            Else
                GetPY = GetPY & "*"
            End If
        Next
    End Function 
    Top 
     
     回复人: yoki(小马哥) ( ) 信誉:100  2003-12-12 11:58:00  得分:0  
     
     
      Private Sub Command1_Click()
    MsgBox pinyin("不到黄河心不死!")
    End Sub
    Function pinyin(ByVal x As String) As String
    On Error Resume Next
    Const hanzi = "啊芭擦搭蛾发噶哈击喀垃妈拿哦啪期然撒塌挖昔压匝座ABCDEFGHJKLMNOPQRSTWXYZZ"
    pinyin = ""
    Dim temp As String, i As Long, j As Long
    i = 1
    Do While i <= Len(x)
    If Mid(x, i, 1) = "座" Then temp = "Z"
    If InStr(",。“”;:?》《!·¥()", Mid(x, i, 1)) > 0 Then temp = ""
    For j = 1 To 23
    If Asc(Mid(x, i, 1)) >= Asc(Mid(hanzi, j, 1)) And Asc(Mid(x, i, 1)) < Asc(Mid(hanzi, j + 1, 1)) Then temp = Mid(hanzi, 24 + j, 1)
    Next
    pinyin = pinyin & " " & temp
    i = i + 1
    temp = ""
    Loop
    pinyin = LCase(pinyin)
    End Function
     
      

  7.   

    方法有两种:If StrComp(String1, String2, vbTextCompare) > 0 Then
        ...
    End If
    或者:Option Compare Text '放在模块的顶部If String1 > String2 Then
        ...
    End If