Dim a As String, b As String a = "1234567890127" b = Right(Space(20) & Left(a, 20), 20) Print b
Option ExplicitPrivate Sub Form_Load() Dim str1 As String str1 = "test" Text1.Text = fixedstr(str1, 20) End Sub Function fixedstr(ByVal sInput As String, ByVal lFixLen) Dim lLen As Long lLen = Len(sInput) If lLen < lFixLen Then fixedstr = sInput & Space(lFixLen - lLen) Else fixedstr = Left(sInput, lFixLen) End If End Function
Private Sub Command1_Click() Dim strAA As String * 20 strAA = "123456789abcdef123456789abcdef" Debug.Print "strAA: "; strAA End Sub运行结果: strAA: 123456789abcdef12345
dim s as string * 20 可以用这个,如果还要考虑双字节单字节,可以用Sstrconv处理一下,如果还要考虑空格补充在字串前后,可用lset、rset语句处理
a = "1234567890127"
b = Right(Space(20) & Left(a, 20), 20)
Print b
Dim str1 As String
str1 = "test"
Text1.Text = fixedstr(str1, 20)
End Sub
Function fixedstr(ByVal sInput As String, ByVal lFixLen)
Dim lLen As Long
lLen = Len(sInput)
If lLen < lFixLen Then
fixedstr = sInput & Space(lFixLen - lLen)
Else
fixedstr = Left(sInput, lFixLen)
End If
End Function
Dim strAA As String * 20
strAA = "123456789abcdef123456789abcdef"
Debug.Print "strAA: "; strAA
End Sub运行结果:
strAA: 123456789abcdef12345
可以用这个,如果还要考虑双字节单字节,可以用Sstrconv处理一下,如果还要考虑空格补充在字串前后,可用lset、rset语句处理