none
我改篇写了c#的一个code 想请教各位我所篇写成vb.net的格式正确吗 RRS feed

  • 问题

  •             char c = '2';
                char answer = '';

                if (Char.IsLetter(c))
                {
                    if (Char.IsLower(c))
                    {
                        answer = '长';
                        MessageBox.Show("Letter");
                    }
                    else
                    {
                        answer = '短';
                        MessageBox.Show("Lower");

                        answer = '没';
                        MessageBox.Show("nothing");
                    }


    这是我根据以上c#所改篇写成vb.net想请教各位该篇写得正确吗?请指点


            Dim c As Char
            Dim answer As Char
            c = CChar(CStr(2))
            answer = CChar("")

            If (Char.IsLetter(c)) Then
                answer = CChar("Letter")
                MsgBox("Letter")
            ElseIf (Char.IsLower(c)) Then
                answer = CChar("Lower")
                MsgBox("Lower")
            Else
                answer = CChar("Nothing")
                MsgBox("Nothing")
            End If




    2020年2月4日 2:42

答案

  • Hi christing,

    根据你的c#代码,你似乎是想判断一个字符是否是字母并且确定它的大小写。如果是这样,我建议你使用以下c#代码。

         private void button1_Click(object sender, EventArgs e)
            {
                char c = 'n';
                char answer;
    
                if (Char.IsLetter(c))
                {
                    MessageBox.Show("Letter");
    
                    if (Char.IsLower(c))
                    {
                        answer = '长';
                        MessageBox.Show("Lower");
                    }
                    else
                    {
                        answer = '短';
                        MessageBox.Show("Uppper");
                    }
                }
                else
                {
                    answer = '没';
                    MessageBox.Show("nothing");
                }
            }

    当然你也可以使用相对应的c#代码。

       Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim c As Char = "n"c
            Dim answer As Char
    
            If Char.IsLetter(c) Then
                MessageBox.Show("Letter")
    
                If Char.IsLower(c) Then
                    answer = "长"c
                    MessageBox.Show("Lower")
                Else
                    answer = "短"c
                    MessageBox.Show("Uppper")
                End If
            Else
                answer = "没"c
                MessageBox.Show("nothing")
            End If
        End Sub

    希望这回帮到你。

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • 已标记为答案 christing 2020年2月5日 8:06
    2020年2月4日 6:17
    版主
  • Hi christing,

    如果是这样,你把我代码中的长和短位置调换一下就可以了。

    想这样:

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim c As Char = "n"c
            Dim answer As Char
    
            If Char.IsLetter(c) Then
                MessageBox.Show("Letter")
    
                If Char.IsLower(c) Then
                    answer = "短"c
                    MessageBox.Show("Lower")
                Else
                    answer = "长"c
                    MessageBox.Show("Uppper")
                End If
            Else
                answer = "没"c
                MessageBox.Show("nothing")
            End If
        End Sub

    如果你对此还有问题,请随时告诉我。

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • 已标记为答案 christing 2020年2月5日 8:06
    2020年2月5日 7:00
    版主

全部回复

  • Hi christing,

    根据你的c#代码,你似乎是想判断一个字符是否是字母并且确定它的大小写。如果是这样,我建议你使用以下c#代码。

         private void button1_Click(object sender, EventArgs e)
            {
                char c = 'n';
                char answer;
    
                if (Char.IsLetter(c))
                {
                    MessageBox.Show("Letter");
    
                    if (Char.IsLower(c))
                    {
                        answer = '长';
                        MessageBox.Show("Lower");
                    }
                    else
                    {
                        answer = '短';
                        MessageBox.Show("Uppper");
                    }
                }
                else
                {
                    answer = '没';
                    MessageBox.Show("nothing");
                }
            }

    当然你也可以使用相对应的c#代码。

       Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim c As Char = "n"c
            Dim answer As Char
    
            If Char.IsLetter(c) Then
                MessageBox.Show("Letter")
    
                If Char.IsLower(c) Then
                    answer = "长"c
                    MessageBox.Show("Lower")
                Else
                    answer = "短"c
                    MessageBox.Show("Uppper")
                End If
            Else
                answer = "没"c
                MessageBox.Show("nothing")
            End If
        End Sub

    希望这回帮到你。

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • 已标记为答案 christing 2020年2月5日 8:06
    2020年2月4日 6:17
    版主
  • @Jack 感谢你的答复 我正尝试篇写一个程序判断一个字符是否是字母并且确定它的大小写

    Dim c As Char = "n"c

    这个code的output 是 lower case 因为"n"是小号

    我尝试使用了你的code button 1 有两个msg box 一个是“长” 一个是“短”

    2020年2月4日 14:25
  • Hi 感谢您的反馈。

    我上面这个程序就是判断一个字符是否是字母并且确定它的大小写。如果字符是字母他会弹出Letter以及upper或者lower,如果不是,他就会弹出nothing表明不是字母。

    你代码中的长和短我不能理解是什么意思。如果还有其他疑问,请告诉我。

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2020年2月5日 3:06
    版主
  • @Jack

    感谢你的回复
     
    你代码中的长和短我不能理解是什么意思。如果还有其他疑问,请告诉我。

    >我代码中长是指(大写),短是指(小写)
    2020年2月5日 4:50
  • Hi christing,

    如果是这样,你把我代码中的长和短位置调换一下就可以了。

    想这样:

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim c As Char = "n"c
            Dim answer As Char
    
            If Char.IsLetter(c) Then
                MessageBox.Show("Letter")
    
                If Char.IsLower(c) Then
                    answer = "短"c
                    MessageBox.Show("Lower")
                Else
                    answer = "长"c
                    MessageBox.Show("Uppper")
                End If
            Else
                answer = "没"c
                MessageBox.Show("nothing")
            End If
        End Sub

    如果你对此还有问题,请随时告诉我。

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • 已标记为答案 christing 2020年2月5日 8:06
    2020年2月5日 7:00
    版主