VB.NET 怎么转换数字对应的汉字

张裸奔 2018-09-18 06:15:21
在取甲方数据时,遇到一个问题,数据库里的字段内容是对应的代码,而我方数据库需要转换过的,我该怎么转换或拼接
比如说:数据库中有个字段为"2,3,4,..."怎么把它替换成"张三,李四,王五,..."附问题源码:
Dim sql As String = "SELECT * FROM dbo.MedInfoTableHis"

Dim dsmedinfo As New DataSet()
dsmedinfo = PubFunc.Getdata(Ironcn_basemz, sql)
For i As Integer = 0 To dsmedinfo.Tables(0).Rows.Count - 1
'medcode = dsmedinfo.Tables(0).Rows(i)("idm").ToString()
'MedSpecial = dsmedinfo.Tables(0).Rows(i)("fzglbs").ToString()
medcode = dsmedinfo.Tables(0).Rows(i)("medonlycode").ToString()
MedSpecial = dsmedinfo.Tables(0).Rows(i)("medspecial").ToString()

--问题是 MedSpecial ="2,3,4"怎么转换
If MedSpecial = "1" Then
MedSpecial = "危"
ElseIf MedSpecial = "2" Then
MedSpecial = "冷"
ElseIf MedSpecial = "3" Then
MedSpecial = "冻"
ElseIf MedSpecial = "4" Then
MedSpecial = "凉"
ElseIf MedSpecial = "5" Then
MedSpecial = "似"
ElseIf MedSpecial = "6" Then
MedSpecial = "暗存"
ElseIf MedSpecial = "7" Then
MedSpecial = "暗"
ElseIf MedSpecial = "8" Then
MedSpecial = "倒"
End If
...全文
359 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
threenewbee 2018-09-19
  • 打赏
  • 举报
回复
Function getsingle(MedSpecial as string) as string
If MedSpecial = "1" Then
MedSpecial = "危"
ElseIf MedSpecial = "2" Then
MedSpecial = "冷"
ElseIf MedSpecial = "3" Then
MedSpecial = "冻"
ElseIf MedSpecial = "4" Then
MedSpecial = "凉"
ElseIf MedSpecial = "5" Then
MedSpecial = "似"
ElseIf MedSpecial = "6" Then
MedSpecial = "暗存"
ElseIf MedSpecial = "7" Then
MedSpecial = "暗"
ElseIf MedSpecial = "8" Then
MedSpecial = "倒"
End If
return MedSpecial
end function

dim arr = split("2,3,4", ",")
MedSpecial = string.join(",", arr.select(function(x) getsingle(x)).toarray())
张裸奔 2018-09-19
  • 打赏
  • 举报
回复
不过在您的基础上,我改出来了,附源码: Dim arr = Split(MedSpecial.ToString(), ",") For j As Integer = 0 To UBound(arr) If MedSpecial2 = "" Then MedSpecial2 = SetMedSpecial(arr(j)) Else MedSpecial2 = MedSpecial2 + "," + SetMedSpecial(arr(j)) + "" End If Next Function SetMedSpecial(ByVal medspecial As String) As String If medspecial = "1" Then medspecial = "危" ElseIf medspecial = "2" Then medspecial = "冷" ElseIf medspecial = "3" Then medspecial = "冻" ElseIf medspecial = "4" Then medspecial = "凉" ElseIf medspecial = "5" Then medspecial = "似" ElseIf medspecial = "6" Then medspecial = "暗存" ElseIf medspecial = "7" Then medspecial = "暗" ElseIf medspecial = "8" Then medspecial = "倒" ElseIf medspecial = "" Then medspecial = " " End If Return medspecial End Function
张裸奔 2018-09-19
  • 打赏
  • 举报
回复
引用 1 楼 caozhy 的回复:
Function getsingle(MedSpecial as string) as string If MedSpecial = "1" Then MedSpecial = "危" ElseIf MedSpecial = "2" Then MedSpecial = "冷" ElseIf MedSpecial = "3" Then MedSpecial = "冻" ElseIf MedSpecial = "4" Then MedSpecial = "凉" ElseIf MedSpecial = "5" Then MedSpecial = "似" ElseIf MedSpecial = "6" Then MedSpecial = "暗存" ElseIf MedSpecial = "7" Then MedSpecial = "暗" ElseIf MedSpecial = "8" Then MedSpecial = "倒" End If return MedSpecial end function dim arr = split("2,3,4", ",") MedSpecial = string.join(",", arr.select(function(x) getsingle(x)).toarray())
提示select不是system.array的成员的报错
张裸奔 2018-09-19
  • 打赏
  • 举报
回复
提示select不是system.array的成员的报错
threenewbee 2018-09-19
  • 打赏
  • 举报
回复
引用 3 楼 qq_38225894 的回复:
[quote=引用 1 楼 caozhy 的回复:]
Function getsingle(MedSpecial as string) as string
If MedSpecial = "1" Then
MedSpecial = "危"
ElseIf MedSpecial = "2" Then
MedSpecial = "冷"
ElseIf MedSpecial = "3" Then
MedSpecial = "冻"
ElseIf MedSpecial = "4" Then
MedSpecial = "凉"
ElseIf MedSpecial = "5" Then
MedSpecial = "似"
ElseIf MedSpecial = "6" Then
MedSpecial = "暗存"
ElseIf MedSpecial = "7" Then
MedSpecial = "暗"
ElseIf MedSpecial = "8" Then
MedSpecial = "倒"
End If
return MedSpecial
end function

dim arr = split("2,3,4", ",")
MedSpecial = string.join(",", arr.select(function(x) getsingle(x)).toarray())



提示select不是system.array的成员的报错 [/quote]
imports system.linq

16,553

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧