2014-04-14 87 views
0

在VB我怎麼能輸入字符串轉換爲字符上下爲輸入「你好」 但像「你好」 我的代碼thiisVB如何輸入字符串轉換爲大寫字符,下

Sub ConvertCase() 
     Dim i As Integer = 0 
     Dim inputVal As String = TextBox1.Text 
     Dim out As String = Label1.Text 
     Do While i > inputVal.Length() 
      If inputVal.Length() Mod 2 = 0 Then 
       out = inputVal.Substring(0, 1).ToUpper 
      End If 
      If inputVal.Length() Mod 2 <> 0 Then 
       out = inputVal.Substring(1).ToLower 
      End If 
      Loop 
     Label1.Text &= out 
    End Sub 

輸出我不知道出了什麼問題> < 謝謝

+0

你的子值都是錯誤 – LittleBobbyTables

+0

我知道-_-這是一個嘗試 你能幫助我嗎? – user3532154

回答

1

你快到了。你只需要追加出

out &= ... 

而子字符串沒有正確完成。

For i As Integer = 0 To inputVal.Length - 1 
     If (i Mod 2) = 0 Then 
      out &= Char.ToUpper(inputVal(i)) 
     Else 
      out &= Char.ToLower(inputVal(i)) 
     End If 
    Next 
+0

非常感謝你<3 the_lotus – user3532154

+1

@ user3532154如果有幫助,請接受它作爲答案;) –

+1

+1。並開始使用字符串生成器。 – Neolisk

1

對於LINQ的戀人:

Label1.Text = New String(TextBox1.Text.Select(Function(c, i) If(i Mod 2 = 0, Char.ToUpper(c), Char.ToLower(c))).ToArray) 
0

試試這個..

Dim str As String = "hello" 
Dim strlength As Integer = str.Length 
Dim ii As Integer = 0 
Dim output As String = "" 
    For Each c As Char In str 
    If ii Mod 2 = 0 Then 
     output += c.ToString.ToUpper 
    Else 
     output += c.ToString.ToLower 
    End If 
    ii += 1 
    Next 
MsgBox(output) 
相關問題