如何拆分数字? [英] How to split a number?
本文介绍了如何拆分数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要一个数字格式,例如333-333-333-3333.
即,当我输入一个13位数字时,它应该使用-
自动拆分给定的数字
每个连字符间距应为3位数.
而且我也不想接受超过13位的数字.
该怎么解决?
问候,
Pawan
Hi,
i want a number format like 333-333-333-3333.
ie., as soon as i enter a 13digit number it should split automatically the given number with -
each hyphen gap should be 3 digits.
and also i don''t want to accept more than a 13digit number.
how to solve this?
Regards,
Pawan
推荐答案
请查看此链接 [
如果您想将一个13位数字拆分为4个数字,那么一定要这样做.
如果这只是进行某些验证或输入的方式,那么我建议您使用带遮罩的文本框进行输入.
面具TextBox ASP.NET控件 [增强的文本框控件 [If you want to split one 13 digit number into 4 numbers, then surely Split is the way.
If it''s just the way for some validation or input taking then I would suggest you to use a masked textbox to take the input.
Mask TextBox ASP.NET Control[^]
Enhanced Textbox Control[^]
There are few similar control based article here at code project itself.
This sort of control would restrict only given number of digits, no less no more in a specified format. Change it as per your need.
您需要使用验证程序来强制使用格式.使用string.Split方法将其转换为单独的数字.You need to use a validator to enforce your format. Use the string.Split method to turn it into seperate numbers.
这篇关于如何拆分数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文