删除字母数字字符串中的前导零

问题描述 投票:-2回答:1

我使用Access 2016.我想使用VBA删除字母右边和数字左边的零(0)。

我有一个包含字母数字字段的表,例如:

A00123050   AB00245098 TH00001250

我想在每个字段中删除前导零(在前导字母后面),如下所示:

A123050  AB245098 TH1250
access-vba
1个回答
0
投票

根据编辑过的问题,就是这么简单。顺便说一句,这假设至少有一个前导字母字符。

Function TrimLeadingZeros(MyString As String) As String
   Dim Idx As Integer
   For Idx = 2 To Len(MyString)
      If IsNumeric(Mid(MyString, Idx, 1)) Then
         Exit For
      End If
   Next
   TrimLeadingZeros = Left(MyString, Idx - 1) & CStr(CLng(Mid(MyString, Idx)))
End Function
© www.soinside.com 2019 - 2024. All rights reserved.