vb点虐 字符串排序 vb字符串反序怎么弄
vb点虐 如何对数据库查询结果记录集排序?
加了单引号就是一个常量字符串了,对于每一行都是一样的
创新互联建站服务项目包括乐平网站建设、乐平网站制作、乐平网页制作以及乐平网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,乐平网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到乐平省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!
像这种放在最前面的字段,order by 1 就可以了
VB 字符串排序
Option Explicit
Private Sub Command1_Click() '排序
Dim i%, j%, S() As String, t As String
ReDim S(Len(Trim(Text1)))
For i = LBound(S) To UBound(S)
S(i) = Mid(Trim(Text1), i + 1, 1)
Next
For i = 0 To UBound(S)
For j = i + 1 To UBound(S)
If S(j) S(i) Then t = S(i): S(i) = S(j): S(j) = t
Next
Text2 = Text2 S(i)
Text2 = Trim(Text2)
Next
End Sub
Private Sub Command2_Click() '读入
Dim Txt As String
Open App.Path "\test12.txt" For Input As #11
Do While Not EOF(11)
Line Input #11, Txt
Text1 = Text1 Txt
Loop
Close #11
End Sub
Private Sub Command3_Click() '追加
Open App.Path "\test12.txt" For Append As #12
Print #12, Text2
Close #12
End Sub
VB怎么使一个字符串按要求排序?就是字符串里面有数字和字母。先按字母在前。数字在后面。字母和数字也
什么都不说,先上效果图——
编码——
Private Sub Command1_Click()
Dim s1 As String, s_num As String, a As String
Dim lennum As Integer, lenuchar As Integer, lenlchar As Integer
Dim s_lchar As String, s_uchar As String
Dim i As Integer, length As Integer, value As Integer
s1 = Text1.Text
s_num = "" '用来存放数字的字符串变量
s_uchar = "" '用来存放大写字母的字符串变量
s_lchar = "" '用来存放小写字母的字符串变量
length = Len(s1)
For i = 1 To length
a = Mid(s1, i, 1)
value = Asc(a)
Text2.Text = value
If value = 48 And value = 57 Then s_num = s_num a
If value = 65 And value = 90 Then s_uchar = s_uchar a
If value = 97 And value = 122 Then s_lchar = s_lchar a
Next i
' 把字符串中的各种字符分类成 数字类,大写字母,小写字母
lennum = Len(s_num)
lenuchar = Len(s_uchar)
lenlchar = Len(s_lchar)
Dim sz() As Integer '定义动态数组
Dim temp As Integer
ReDim sz(1 To lennum) As Integer '定义数组供 数字的ASCII码
For i = 1 To lennum
a = Mid(s_num, i, 1)
sz(i) = Asc(a)
Next i
For i = lennum To 1 Step -1 '最常用的冒泡排序法
For j = 1 To i - 1
If sz(j) sz(j + 1) Then temp = sz(j): sz(j) = sz(j + 1): sz(j + 1) = temp
Next j
Next i
s_num = "" '清空s_num ,因为要重新排列了
For i = 1 To lennum
s_num = s_num Chr(sz(i))
Next i
ReDim sz(1 To lenuchar) As Integer '重新定义数组供 大写字母的ASCII码,接下来程序思路与上面类似
For i = 1 To lenuchar
a = Mid(s_uchar, i, 1)
sz(i) = Asc(a)
Next i
For i = lenuchar To 1 Step -1
For j = 1 To i - 1
If sz(j) sz(j + 1) Then temp = sz(j): sz(j) = sz(j + 1): sz(j + 1) = temp
Next j
Next i
s_uchar = ""
For i = 1 To lenuchar
s_uchar = s_uchar Chr(sz(i))
Next i
ReDim sz(1 To lenlchar) As Integer '重新定义数组供 小写字母的ASCII码,接下来程序思路与上面类似
For i = 1 To lenlchar
a = Mid(s_lchar, i, 1)
sz(i) = Asc(a)
Next i
For i = lenlchar To 1 Step -1
For j = 1 To i - 1
If sz(j) sz(j + 1) Then temp = sz(j): sz(j) = sz(j + 1): sz(j + 1) = temp
Next j
Next i
s_lchar = ""
For i = 1 To lenlchar
s_lchar = s_lchar Chr(sz(i))
Next i
Text2.Text = s_uchar s_lchar s_num
End Sub
该程序主要运用了Asc()函数获得ASCII码来分辨字母与数字,用 动态数组和重定义来多次运用数组进行排序(冒泡排序法)和赋值操作,用chr()函数还原字符串。
我的程序有点略长,中间有少许重复部分,但我觉得思路比较清晰易懂,适合初学者。你也可以试着自己改进。
分享文章:vb点虐 字符串排序 vb字符串反序怎么弄
链接地址:http://myzitong.com/article/ddcjchs.html