如何在varchar中拆分值 [英] how do I split a value in varchar
本文介绍了如何在varchar中拆分值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我想分割从文本框中获取的值并将其保存在两个不同的变量中。我在一个文本框中有一个10位数的电话号码,我想将前3位数保存到一个名为code的变量中,然后将7位数保存到一个名为number的变量中。请指定一个概念来执行此操作。通过使用哪种方法可以实现这一点??
解决方案
如果它总是10个字符,那么只需使用string.Substring:
string code = tbNumber.Text.Substring( 0 , 3 跨度>);
string number = tbNumber.Text.SubString( 3 );
你好
请使用以下代码
< pre lang =cs> string sPhoneNumber = 1234567890 跨度>;
string sCode = ;
string sNumber = ;
if (sPhoneNumber.Length == 10 )
{
sCode = sPhoneNumber.Substring( 0 , 3 );
sNumber = sPhoneNumber.Substring( 3 );
}
代码前三位数,最后一位数为7位。
Hello, I want to split a value taken from a textbox and save it in two different variables. I have a phone number of 10 digit eneterd in a textbox and I want to save first 3 digit into a variable called "code" and next 7 digit into a variable called number. Please specify a concept to do this. By using which methodology can I achieve this??
解决方案
If it's always 10 characters then just use string.Substring:
string code = tbNumber.Text.Substring(0, 3); string number = tbNumber.Text.SubString(3);
Hello
Please use below code
string sPhoneNumber = "1234567890"; string sCode = ""; string sNumber = ""; if (sPhoneNumber.Length==10) { sCode = sPhoneNumber.Substring(0, 3); sNumber = sPhoneNumber.Substring(3); }
Code have the first three digit and number have the last 7 digit.
这篇关于如何在varchar中拆分值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文