如何将逗号分隔的数字从文本框转换为字母

时间:2013-04-30 10:35:27

标签: asp.net vb.net visual-studio visual-studio-2008

我有一个文本框,显示值为10,20,30,即

 textbox1.text="10,20,30,50"

预定义值:10-A, 20-B, 30-$, 50-*

我希望label1中显示的值符合textbox1值,因此现在根据此textbox1

Label1.text="AB$*"

我想在Vb.net(asp.net)中编写代码

1 个答案:

答案 0 :(得分:0)

在c#

string textboxval=textbox1.text;
string[] words = textboxval.Split(',');
foreach (string word in words)
 {
    int no=int.parse(word);
    switch(no)
    {
     case 10:
       label1.text += "A";
       break;
     case 20:
       label1.text += "B";
       break;
     case 30:
       label1.text += "$";
       break;
     case 50:
       label1.text += "*";
       break;
    }
 }

in vb

Dim textboxval As String = textbox1.text
Dim words As String() = textboxval.Split(","C)
For Each word As String In words
Dim no As Integer = Integer.parse(word)
Select Case no
    Case 10
        label1.text += "A"
        Exit Select
    Case 20
        label1.text += "B"
        Exit Select
    Case 30
        label1.text += "$"
        Exit Select
    Case 50
        label1.text += "*"
        Exit Select
End Select
Next