本帖最后由 xnwxq 于 2009-8-23 17:29 编辑
去除字符串中的空格,在上位机设计中会经常使用到,尤其是在报文发送的功能上尤其要注意!虽然简单但是应该作为小的总结记录下来!
'去除字符串中的空格(方法一)
Public Function DelBlank(SearchString As String)
DelBlank = Replace(SearchString, Chr(32), "")
End Function
'去除字符串中的空格(方法二)
Public Function DelBlank(SearchString As String)
Dim Strtemp As String
Dim LenTemp As Integer
Dim Blank() As String
LenTemp = Len(SearchString)
Strtemp = SearchString
ReDim Blank(LenTemp - 1)
For i = 1 To LenTemp
Strtemp = Left(Strtemp, 1)
If Not Strtemp = " " Then
Blank(i - 1) = Strtemp
End If
Strtemp = Right(SearchString, LenTemp - i)
Next
For i = 0 To LenTemp - 1
DelBlank = DelBlank + Blank(i)
Next
DelBlank = Trim(DelBlank)
End Function |