下面是个VB程序,怎么修改是句子中出现一个以上的空格时,整理后仅保留一个空格Dim n As Integer
Dim t0 As String, t1 As String
If KeyAscii <> 13 Then
Else
txtArrange = ""
n = 1
t0 = "."
t1 = Mid(txtInput, n, 1)
Do While n <= Len(txtInput)
t1 = LCase(t1)
If t0 = "." Or t0 = "?" Then t1 = UCase(t1)
txtArrange = txtArrange + t1
n = n + 1
t0 = t1
t1 = Mid(txtInput, n, 1)
Loop
End If
Dim t0 As String, t1 As String
If KeyAscii <> 13 Then
Else
txtArrange = ""
n = 1
t0 = "."
t1 = Mid(txtInput, n, 1)
Do While n <= Len(txtInput)
t1 = LCase(t1)
If t0 = "." Or t0 = "?" Then t1 = UCase(t1)
txtArrange = txtArrange + t1
n = n + 1
t0 = t1
t1 = Mid(txtInput, n, 1)
Loop
End If
Dim m As Integer
Dim t0 As String, t1 As String
If KeyAscii <> 13 Then
Else
txtArrange = ""
m=0
n = 1
t0 = "."
t1 = Mid(txtInput, n, 1)
Do While n <= Len(txtInput)
if t1=" " then m=m+1
t1 = LCase(t1)
If t0 = "." Or t0 = "?" Then t1 = UCase(t1)
txtArrange = txtArrange + t1
n = n + 1
if m<=1 then
t0 = t1
endif
t1 = Mid(txtInput, n, 1)
Loop
End If
MergeX = ""
Dim i As Long
Dim currentChar As String, lastChar As String
currentChar = ""
lastChar = ""
For i = 1 To Len(sIn)
currentChar = Mid$(sIn, i, 1)
If lastChar = sFind And currentChar = lastChar Then
Else
MergeX = MergeX & currentChar
End If
lastChar = currentChar
Next
End FunctionIf KeyAscii <> 13 Then
Else
txtArrange = MergeX(txtInput)
End If
GetString = Replace(s, sFind, "`", 1, 1)
GetString = Replace(GetString, sFind, "")
GetString = Replace(GetString, "`", sFind)
End Function If KeyAscii <> 13 Then
Else
'........
txtArrange = GetString(txtInput)
Debug.Print txtArrange
End If
Option ExplicitPrivate Sub txtInput_KeyPress(KeyAscii As Integer) If (KeyAscii = 13) Then txtArrange.Text = FormatText(txtInput.Text)End SubPrivate Function FormatText(strIn$) As String
Dim m&, n&, strTemp$
strTemp = LCase$(strIn)
Mid$(strTemp, 1, 1) = UCase$(Mid$(strTemp, 1, 1))
While (InStr(1, strTemp, " ") > 0)
strTemp = Replace(strTemp, " ", " ")
Wend
m = Len(strTemp)
n = InStr(1, strTemp, ".") + 1
If (n < m) Then
While (n > 1)
Do
If (Asc(Mid$(strTemp, n, 1)) <> 32) Then Exit Do
n = n + 1
Loop While (n < m)
Mid$(strTemp, n, 1) = UCase$(Mid$(strTemp, n, 1))
n = InStr(n, strTemp, ".") + 1
Wend
End If
n = InStr(1, strTemp, "?") + 1
If (n < m) Then
While (n > 1)
Do
If (Asc(Mid$(strTemp, n, 1)) <> 32) Then Exit Do
n = n + 1
Loop While (n < m)
Mid$(strTemp, n, 1) = UCase$(Mid$(strTemp, n, 1))
n = InStr(n, strTemp, ".") + 1
Wend
End If
FormatText = strTemp
End Function