我发现了很多关于如何填充字符串的建议,Access 2010
但没有找到关于如何将带有空格的可变长度字符串填充到预定的总字符串长度的建议。
例子:
Total length = 55,
if string len = 15, then pad " " x 40 (15+40=55)
if string len = 35, then pad " " x 20 (35+20=55) etc
我可以编写一个函数来做到这一点,但我想知道是否已经内置了一个!
我发现了很多关于如何填充字符串的建议,Access 2010
但没有找到关于如何将带有空格的可变长度字符串填充到预定的总字符串长度的建议。
例子:
Total length = 55,
if string len = 15, then pad " " x 40 (15+40=55)
if string len = 35, then pad " " x 20 (35+20=55) etc
我可以编写一个函数来做到这一点,但我想知道是否已经内置了一个!
有点数学?
[x] & space(55 - len([x]))
有一个本机功能:
Dim Total As String
Dim Content As String
Total = Space(55)
Content = "Some Content"
RSet Total = Content
Debug.Print Chr(34) & Total & Chr(34)
' Will return:
' "Some Content "
甚至更简单:
Dim Total As String * 55
Dim Content As String
Content = "Some Content"
RSet Total = Content
Debug.Print Chr(34) & Total & Chr(34)
' Will return:
' "Some Content "
SELECT
(MyTest.[Name1]) & SPACE(55-LEN(MyTest.[Name1])) +
(MyTest.[Name2]) & SPACE(55-Nz(LEN(MyTest.[Name2]), 0)) +
(MyTest.[Name3]) & SPACE(55-LEN(MyTest.[Name3]))
FROM MyTest;