如何使用if语句检查字符串数组是否有数字? [英] How do I use if statement to check if string array has a number?

查看:211
本文介绍了如何使用if语句检查字符串数组是否有数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的共享子,strCitationNumbers字符串数组可以有一个数字或不匹配文本。



我想添加if语句来检查strCitationNumbers中是否有数字。

如果在strCitationNumbers中找到一个数字,我想输出一条错误消息,说找到重复的案例。

我该怎么办?

My shared sub, the strCitationNumbers string array can have a number or 'No match' text.

I would like to add if statement to check if strCitationNumbers has a number in it.
If a number is found in the strCitationNumbers, I want to output an error message saying 'Duplicate case found'.
How do I do it?

Shared Sub TestCitationGetCaseNumber()
         Dim strCitationNumbers() As String
        Dim strCitationNumber As String = "2770043451123"
 strCitationNumbers = Msc.Integration.Mncis.Library.v4.Citation.GetCaseNumbersForCitation(strCitationNumber, False)   
End Sub





我的尝试:



这是我的代码。





What I have tried:

Here is my code.

Shared Sub TestCitationGetCaseNumber()
         Dim strCitationNumbers() As String
        Dim strCitationNumber As String = "2770043451123"
 strCitationNumbers = Msc.Integration.Mncis.Library.v4.Citation.GetCaseNumbersForCitation(strCitationNumber, False)   
End Sub

推荐答案

简单方法是使用TryParse:Int32 .TryParse方法(String,Int32)(系统) [ ^ ]

Easy way is to use TryParse: Int32.TryParse Method (String, Int32) (System)[^]
Dim numberIfAny as Integer
Dim isANumber As Boolean = Int32.TryParse(strCitationNumber, numberIfAny)



检查isANumber结果时,你可以做你喜欢的事情


You can do what you like when you check the isANumber result


这篇关于如何使用if语句检查字符串数组是否有数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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