'strTmp 为字符串,nLen是你要设定的长度 Public Function FixLenString(ByVal strTmp As String, ByVal nLen As Integer) As String strTmp = IIf(nLen <= Len(strTmp), Left(strTmp, nLen), strTmp & Space(nLen - Len(strTmp))) End Function调用:debug.print FixLenString("abc",6)
调用下面的函数:?FIXStringLen("abcdebfeg",6) abcdeb '-------------------------------- '将字符串变成指定长度 '-------------------------------- Function FIXStringLen(ByVal str1 As String, byval fixLen As Long) As String If Len(str1) > fixLen Then FIXStringLen = Left(str1, fixLen) Else FIXStringLen = str1 & Space(fixLen - Len(str1)) End If End Function
你就去判断字符串的长度啊。当字符串长度<6,就在后面加空格 >=6的话就取前面6位咯
晕~~,函数返回都写错了:) Public Function FixLenString(ByVal strTmp As String, ByVal nLen As Integer) As String FixLenString = IIf(nLen <= Len(strTmp), Left(strTmp, nLen), strTmp & Space(nLen - Len(strTmp))) End Function
Public Function FixLenString(ByVal strTmp As String, ByVal nLen As Integer) As String
strTmp = IIf(nLen <= Len(strTmp), Left(strTmp, nLen), strTmp & Space(nLen - Len(strTmp)))
End Function调用:debug.print FixLenString("abc",6)
abcdeb
'--------------------------------
'将字符串变成指定长度
'--------------------------------
Function FIXStringLen(ByVal str1 As String, byval fixLen As Long) As String
If Len(str1) > fixLen Then
FIXStringLen = Left(str1, fixLen)
Else
FIXStringLen = str1 & Space(fixLen - Len(str1))
End If
End Function
>=6的话就取前面6位咯
Public Function FixLenString(ByVal strTmp As String, ByVal nLen As Integer) As String
FixLenString = IIf(nLen <= Len(strTmp), Left(strTmp, nLen), strTmp & Space(nLen - Len(strTmp)))
End Function
不用判断长度,然后后边加空格的方法啊主要是不知道如何用Format实现,哪位贴一个出来,最好一个语句解决问题啊
left("abcdefgh" & space(6),6)
dim s as string * 6
s="abc"