Space 函式 (Visual Basic)

更新:2007 年 11 月

傳回由指定空格數量所組成的字串。

Public Shared Function Space(ByVal Number As Integer) As String

參數

  • Number
    必要項。Integer 運算式。字串中的空格數量。

例外狀況

例外狀況類型

錯誤代碼

條件

ArgumentException

5

Number < 0.

如果將使用非結構化錯誤處理的 Visual Basic 6.0 應用程式升級,請參閱「錯誤代碼」資料行 (您可以將錯誤代碼與 Number 屬性 (Err 物件) 比對)。但是,請盡可能考慮以 Visual Basic 的結構化例外處理概觀 取代這類錯誤控制項。

備註

Space 函式對於格式化輸出及清除固定長度字串中的資料非常好用。

範例

這個範例會使用 Space 函式,以傳回由指定空格數量所組成的字串。

Dim TestString As String
' Returns a string with 10 spaces.
TestString = Space(10)
' Inserts 10 spaces between two strings.
TestString = "Hello" & Space(10) & "World"

需求

命名空間 (Namespace)︰Microsoft.VisualBasic

模組:Strings

組件 (Assembly):Visual Basic Runtime Library (在 Microsoft.VisualBasic.dll 中)

請參閱

參考

字串操作摘要

SPC 函式

ArgumentException