如何将Vb.Net中的数字拆分为两个 [英] How Can I Split A Number In Vb.Net Into Two

查看:142
本文介绍了如何将Vb.Net中的数字拆分为两个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检查条形码是否以27开头。如果是,我需要在文本框中输入此条形码的前6位数,其他文本框中的其余数字如何在vb.net中执行此操作?任何帮助将不胜感激

我如何使用split方法来做那个或正则表达式或什么?

解决方案

你知道吗String类型有一个Substring方法?



https://msdn.microsoft.com/en-us/library/aka44szs(v = vs.110).aspx [ ^ ]



所以伪代码(即粗略的代码,实际上不是任何语言,除了字符串Substr和Remove ARE VB)



 if barCodeString .Substr(0,2)=='27'
//将条形码的前6个字符放入TextBox 1
TextBox1.Text = barCodeString.Substr(0,6)
//创建一个临时字符串,以便不改变原始
字符串TempString = barCodeString
//删除前6个字符
TempString.Remove(0,6)
//将剩余物放入TextBox2
TextBox2.Text = TempString
end





为何复杂化正则表达式的东西?你只需要将我所投入的内容转换为适当的VB


guys i need to check if a barcode number starts with 27. if it does, i need to have the first 6 digitsnof this barcode in a textbox and the rest digits in another textbox how can i do that in vb.net? any help would be appreciated
how can i use the split method to do that or regular expressions or something?

解决方案

you do know the String type has a Substring method ?

https://msdn.microsoft.com/en-us/library/aka44szs(v=vs.110).aspx[^]

so in pseudocode (ie rough code thats not really any language except the string Substr and Remove ARE VB)

if barCodeString.Substr(0,2) == '27'
    // Put 1st 6 chars of bar code into TextBox 1
    TextBox1.Text = barCodeString.Substr(0,6)
    // Create a temporary String so as to not alter original
    String TempString = barCodeString
    // Delete the 1st 6 characters
    TempString.Remove(0,6)
    // Put the Remainder in TextBox2
    TextBox2.Text = TempString
end



Why complicate things with Regular expressions ? you just have to turn what Ive put into proper VB


这篇关于如何将Vb.Net中的数字拆分为两个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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