字符串数组和字符串中的问题 [英] Problem in String Array and Strings

查看:96
本文介绍了字符串数组和字符串中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

dim AllPlayerInfo as string()

AllPlayerInfo = PlayerFile.split(vbcrlf)

If Not AllPlayerInfo.Length = 0 Then

            If AllPlayerInfo(1) = TextBox1.Text Then

                If AllPlayerInfo(2) = TextBox2.Text Then

                    MsgBox("Hello " & TextBox1.Text)

                    Return True
                    Exit Function

                End If

            End If

        End If
  MsgBox("Can't Find This Account .. , MsgBoxStyle.Information)

    Return False











问题是它显示了找不到msgbox

甚至AllPlayerInfo(1)= TextBox1.Text和AllPlayerInfo(2)= TextBox2.Text





如何解决这个问题






The problem is it show the can't find msgbox
even AllPlayerInfo(1) = TextBox1.Text and AllPlayerInfo(2) = TextBox2.Text


How can i solve this

推荐答案

试试这个:



Try this:

Dim AllPlayerInfo As String()

AllPlayerInfo = PlayerFile.Split(vbCrLf.ToCharArray, StringSplitOptions.RemoveEmptyEntries)

If Not AllPlayerInfo.Length = 0 AndAlso AllPlayerInfo(1).ToLower() = TextBox1.Text.ToLower() AndAlso AllPlayerInfo(2).ToLower() = TextBox2.Text.ToLower() Then
      MsgBox("Hello " & TextBox1.Text)
      Return True
Else
      MsgBox("Can't Find This Account .. ", MsgBoxStyle.Information)
      Return False
End If





你的留言箱总是显示,因为你已经将它写在IF..THEN..ELSE语句的范围之外。通过这样做,它将显示iff长度属性返回零,这是你的意图我猜。



希望它有所帮助!



编辑



首先,代码已被修改。我已经想出了一些事情就是你的代码。



1)当已经存在RETURN语句时,不需要EXIT FUNCTION。所以删除它。

2)更改:





Your messagebox always displays becuase you have written it outside the scope of IF..THEN..ELSE statement. By doing this it will display iff the "Length" property returns zero, which is your intentions i guess.

Hope it helps!

EDIT

First of all, the code has been modified. I have figured out a couple of things is your code.

1) No need to EXIT FUNCTION when there is already RETURN statement present. So remove it.
2) Change:

PlayerFile.Split(vbCrLf)





to:





to :

PlayerFile.Split(vbCrLf.ToCharArray, StringSplitOptions.RemoveEmptyEntries)



我的猜测是你在下一个未通过比较的数组元素前面附加了一个vbLf。所以这样做会解决这个问题。



3)当我们比较字符串时,最好将它设为UPPER case或LOWER case,所以我用过< b> .ToLower(),具体取决于区分大小写。请根据您的情况进行调整。



4)最好为每个IF..ELSE IF条件定义ELSE部分,它有助于覆盖其余部分因此,我没有定义三个ELSE语句,而是将条件最小化为一个IF..ELSE语句。



检查出来。希望它有所帮助!



如果您需要进一步的帮助,请提供变量的样本值和所需的结果示例。



快乐编码!!!


my guess is that you are getting a "vbLf" appended in front of the next array element which fails the comparison. So doing it this way will fix this issue.

3) When we compare strings it is preferred to make it either UPPER case or LOWER case, so i have used .ToLower(), depending upon case sensitivity. Please adjust it as per your scenario.

4) It is good to define ELSE part for each IF..ELSE IF condition, it helps to cover the rest of the cases so instead of defining three ELSE statements i have minimized the condition to one IF..ELSE statement.

Check it out. Hope it helps!

If you need further assistance please come up with sample values of variables and the desired result examples.

Happy coding!!!


dim AllPlayerInfo as string()

AllPlayerInfo = PlayerFile.split(vbcrlf)

If Not AllPlayerInfo.Length = 0 Then

            If AllPlayerInfo(0) = TextBox1.Text Then

                If AllPlayerInfo(1) = TextBox2.Text Then

                    MsgBox("Hello " & TextBox1.Text)

                    Return True
                    Exit Function

                End If

            End If
Else
  MsgBox("Can't Find This Account .. , MsgBoxStyle.Information)
End If

Return False


这篇关于字符串数组和字符串中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆