excel - 在 Excel 中翻译数字字符串

标签 excel vba string

所以基本上我在一列中有18位数字。此字符串表示给定人员在此表中的角色:

100000000000000000 -> Admin

000000000010000000 -> TL

000000000100000000 -> DEV

000000010000000000 -> Viewer

000000100000000000 -> TE

000000000000100000 -> TA

从字符串的长度来看,我认为它们是更多的角色,这些角色现在并不重要,但以后可能会更重要。问题是,可以有任何角色组合,例如:
000000010100000000 -> DEV, Viewer

000000100100000000 -> DEV, TE

100000010000100000 -> Admin, TA, Viewer

我的任务是将每个字符串翻译成角色。

因为我知道哪个位置代表哪个角色,所以我可以在字符串中搜索“1”并通过“1”的位置添加代表角色。这是我的问题,我不知道 VB 是否提供了搜索字符串以查找给定字符的多个外观并保存它们的相对位置的可能性。如果是这样,那么只需为每个角色添加“if then”即可。如果没有,我就像现在一样迷路了。

最佳答案

这是建立角色的一种方法:

Private Sub Test()
   Dim role As String
   Dim roles As String
   Dim i As Integer

   role = "000000010100000000"

   For i = 1 To Len(role)
      If i = 1 And Mid(role, i, 1) = "1" Then roles = roles & "Admin, "
      If i = 7 And Mid(role, i, 1) = "1" Then roles = roles & "TE, "
      If i = 8 And Mid(role, i, 1) = "1" Then roles = roles & "Viewer, "
      If i = 10 And Mid(role, i, 1) = "1" Then roles = roles & "DEV, "
      If i = 11 And Mid(role, i, 1) = "1" Then roles = roles & "TL, "
      If i = 13 And Mid(role, i, 1) = "1" Then roles = roles & "TA, "
   Next

   MsgBox Left(roles, Len(roles) - 2)
End Sub

关于excel - 在 Excel 中翻译数字字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60338936/

相关文章:

java - 无法弄清楚为什么我收到 StringIndexOutOfBoundsException

java - Excel POI 3.5 WorkBook Java 堆空间异常?

excel - VLookup - Visual Basic - 如何设置范围

excel - 如何从weka打开excel文件

sql - ALTER USER 给出语法错误

c# - 有效地获取格式化的单元格值

java - 为什么我的字符串到字符串比较失败?

python - 将字符串转换为嵌套列表

excel - matlab使用activex接口(interface)自动保存excel文件

excel - 如何使用 VBA 将文件上传到 OneDrive Business (Sharepoint)