2014-04-14 89 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) 
相关问题