vb题目:输入字符串s,将s中的前导空格和尾随空格删去,中间连续多个空格缩为一个空
5个回答
展开全部
Private Sub Command1_Click()
Dim s1 As String, s2 As String, i As Integer, j As Integer
s1 = Trim(InputBox("输入字符串"))
For i = 1 To Len(s1)
j = 0
If Mid(s1, i, 1) = " " Then
If i < Len(s1) Then
If Mid(s1, i + 1, 1) = " " Then j = 1 Else j = 0
End If
End If
If j = 0 Then s2 = s2 + Mid(s1, i, 1)
Next
Text1.Text = s2
End Sub
Dim s1 As String, s2 As String, i As Integer, j As Integer
s1 = Trim(InputBox("输入字符串"))
For i = 1 To Len(s1)
j = 0
If Mid(s1, i, 1) = " " Then
If i < Len(s1) Then
If Mid(s1, i + 1, 1) = " " Then j = 1 Else j = 0
End If
End If
If j = 0 Then s2 = s2 + Mid(s1, i, 1)
Next
Text1.Text = s2
End Sub
追问
一辆重型卡车欲通过1000公里的沙漠,卡车耗油量为1公升/公里,卡车总载油量为500公升,显然卡车装一次油是通过不了沙漠的。因此司机必须在沿途设立几个储油点,使卡车能顺利通过沙漠。试问司机如何建这些储油点?每个储油点应该储多少升油?才能使用卡车以最小耗油量的代价通过沙漠?这题再帮下啊哈哈还是VB
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
s = Trim(Text1)
j = 2
For i = 2 To Len(s)
If Mid(s, i, 1) <> " " Or Mid(s, i - 1, 1) <> " " Then
Mid(s, j, 1) = Mid(s, i, 1)
j = j + 1
End If
Next i
Text2 = Left(s, j)
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Dim s As String
s = " a b c d "
s = MyTrim(s)
MsgBox s
End Sub
Private Function MyTrim(s As String) As String
MyTrim = Trim(s)'去掉首位空格
Do While InStr(1, MyTrim, " ") > 0 '循环直到检查到没有两个连续的空格
MyTrim = Replace(MyTrim, " ", " ")
Loop
End Function
Dim s As String
s = " a b c d "
s = MyTrim(s)
MsgBox s
End Sub
Private Function MyTrim(s As String) As String
MyTrim = Trim(s)'去掉首位空格
Do While InStr(1, MyTrim, " ") > 0 '循环直到检查到没有两个连续的空格
MyTrim = Replace(MyTrim, " ", " ")
Loop
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Dim str1 As String
Dim str2() As String
str1 = " sddd llkk " '示范字符串,可以改成其他的或者由textbox输入
str2 = Split(Trim(str1), " ")
Text1.Text = str2(LBound(str2)) & " " & Trim(str2(UBound(str2)))
End Sub
Dim str1 As String
Dim str2() As String
str1 = " sddd llkk " '示范字符串,可以改成其他的或者由textbox输入
str2 = Split(Trim(str1), " ")
Text1.Text = str2(LBound(str2)) & " " & Trim(str2(UBound(str2)))
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
u
追问
能行不,求教啊
追答
10个
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询