以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]数值转换的 内部函数的问题~  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=27892)

--  作者:gaoyong30000
--  发布时间:2013/1/13 16:05:00
--  [求助]数值转换的 内部函数的问题~
 我项目里有一个数值转换的内部函数! 代码如下:

Dim Val As String = Args(0)
Dim cs() As String = New String() { "1","2","3","4","5","6","7","8","9"}
Dim ns() As String = New String() {"01","02","03","04","05","06","07","08","09"}
If Args(0) < 10 Then
    For n As Integer = 0 To cs.Length -1
        If cs(n) = Args(0) Then
            Return ns(n)
        End If
    Next
Else
    Return Args(0)
End If

现在遇到一个问题   需要从 cs()  从1到10000

ns()   是0001,0002,0003  到 9999这种格式

请问代码该如何修改??

--  作者:qtcks
--  发布时间:2013/1/13 18:30:00
--  
Dim cs() As String = New String() { "1","2","3","4","5","6","7","8","9"}
Dim ns() As String = New String() {"01","02","03","04","05","06","07","08","09"}

这种强规则的转换,不建议用这种方式。
直接使用格式化就行了。

--  作者:lin_hailun
--  发布时间:2013/1/14 14:28:00
--  
 补0操作不必这样麻烦吧?

参考下:

Dim i As Integer = 98
Dim str As String = format(i, "00000")
msgbox(str)

--  作者:qtcks
--  发布时间:2013/1/14 15:31:00
--  
Dim Val As String = Args(0)
Dim ns() As String = New String() {"01","02","03","04","05","06","07","08","09"}
If ns(Val) isnothing Then
      Return ns(Val)
End If