如果是列的话是可以的,在a1:a10中,任意的空格都可以去除,行的空格应该也可以去除:
创新互联建站专注骨干网络服务器租用十多年,服务更有保障!服务器租用,成都服务器托管 成都服务器租用,成都服务器托管,骨干网络带宽,享受低延迟,高速访问。灵活、实现低成本的共享或公网数据中心高速带宽的专属高性能服务器。
Public Sub ww() '
Dim ar, arr
ar = [a1:a10]
arr = Split(Application.Trim(Join(Application.Transpose(ar))))
Debug.Print Join(arr)
End Sub
Erase 数组名
要注意,如果是固定数组,则所有元素的值被初始化(字符型为空字符串,数值型为0),数组的大小是不变的;如果是动态数组,则所有元素被删除,内存空间被回收,要重新ReDim才能使用。Private Sub Form_Click()Dim a(9) As Integer, i As IntegerRandomizePrint "清除前:"For i = 0 To 9 a(i) = Rnd * 100 Print a(i);NextPrintErase aPrint "清除后"For i = 0 To 9 Print a(i);NextPrintEnd Sub
你是要把连续多个空格,变换成只需要一个空格,那么:
do while Instr(tStr," ")0
tStr = Replace(tStr, " ", " ") '用一个空格,替换2个空格
loop
来给你写了个函数,拿去用,不谢
Function RemoveAt(Of T)(ByVal arr As T(), ByVal index As Integer) As T()
Dim uBound = arr.GetUpperBound(0)
Dim lBound = arr.GetLowerBound(0)
Dim arrLen = uBound - lBound
If index lBound OrElse index uBound Then
Throw New ArgumentOutOfRangeException( _
String.Format("Index must be from {0} to {1}.", lBound, uBound))
Else
Dim outArr(arrLen - 1) As T
Array.Copy(arr, 0, outArr, 0, index)
Array.Copy(arr, index + 1, outArr, index, uBound - index)
Return outArr
End If
End Function