标题:变量s中的0-9为什么没有被替换,如何改?
只看楼主
yuma
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:银河系
等 级:贵宾
威 望:33
帖 子:1883
专家分:2904
注 册:2009-12-22
结帖率:89.13%
 问题点数:0 回复次数:4 
变量s中的0-9为什么没有被替换,如何改?
变量s中的0-9为什么没有被替换,如何改?

程序代码:
Private Sub Form_Load()
Dim s As String
s = "73203d2022d6d0bbaac"
For i = 1 To Len(s)
a = Mid(s, i, 1)
a = Replace(a, "0", "f")
a = Replace(a, "1", "e")
a = Replace(a, "2", "d")
a = Replace(a, "3", "c")
a = Replace(a, "4", "b")
a = Replace(a, "5", "a")
a = Replace(a, "6", "9")
a = Replace(a, "7", "8")
a = Replace(a, "8", "7")
a = Replace(a, "9", "6")
a = Replace(a, "a", "5")
a = Replace(a, "b", "4")
a = Replace(a, "c", "3")
a = Replace(a, "d", "2")
a = Replace(a, "e", "1")
a = Replace(a, "f", "0")
b = b & a
Next
Debug.Print b
End Sub
搜索更多相关主题的帖子: 变量 替换 Replace Sub Next 
2021-08-26 21:20
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4912
专家分:29900
注 册:2008-10-15
得分:0 
a = Replace(a, "0", "f")
0变成了f
然后最后
a = Replace(a, "f", "0")
f又变成了0了,包括原来的f都变成了0
最终,0 还是 零,f变成了0
所以,最终是 0-7没变,8-f都变了。

----------------------------
换的过程应该是,每二个一组交换,交换需要引入新的字符
程序代码:
'---0 f ----
a = Replace(a, "0", "s")
a = Replace(a, "f", "0")
a = Replace(a, "s", "f")
'---1 e ----
a = Replace(a, "1", "s")
a = Replace(a, "e", "1")
a = Replace(a, "s", "e")
........





授人于鱼,不如授人于渔
早已停用QQ了
2021-08-26 22:29
yuma
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:银河系
等 级:贵宾
威 望:33
帖 子:1883
专家分:2904
注 册:2009-12-22
得分:0 
s = "73203d2022d6d0bbaac"
For i = 1 To Len(s)
a = Mid(s, i, 1)
If a = "0" Then b = "f"
If a = "1" Then b = "e"
If a = "2" Then b = "d"
If a = "3" Then b = "c"
If a = "4" Then b = "b"
If a = "5" Then b = "a"
If a = "6" Then b = "9"
If a = "7" Then b = "8"
If a = "8" Then b = "7"
If a = "9" Then b = "6"
If a = "a" Then b = "5"
If a = "b" Then b = "4"
If a = "c" Then b = "3"
If a = "d" Then b = "2"
If a = "e" Then b = "1"
If a = "f" Then b = "0"
c = c & b
Next
MsgBox c

[此贴子已经被作者于2021-11-29 13:43编辑过]


心生万象,万象皆程序!
本人计算机知识网:http://bbs.为防伸手党,本站已停止会员注册。
2021-08-27 06:16
cwa9958
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:67
帖 子:247
专家分:1228
注 册:2006-6-25
得分:0 
用select case语句会好看点。
2021-08-30 08:38
apull
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:三体星系
等 级:版主
威 望:185
帖 子:1404
专家分:8479
注 册:2010-3-16
得分:0 
程序代码:
Private Sub Form_Load()
    Dim s As String
    s = "73203d2022d6d0bbaac"
    For i = 1 To Len(s)
        a = Mid(s, i, 1)
        If (a >= "0" And a <= "5") Then
            a = Chr(Asc("f") - (Asc(a) - Asc("0")))
        ElseIf (a >= "6" And a <= "9") Then
            a = Chr(Asc("9") - (Asc(a) - Asc("6")))
        ElseIf (a >= "a" And a <= "f") Then
            a = Chr(Asc("5") - (Asc(a) - Asc("a")))
        End If
        b = b & a
    Next
    Debug.Print b
End Sub
2021-08-30 10:16



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-506664-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.071010 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved