在asp.net 2.0中可以用split方法

 

 }, StringSplitOptions.RemoveEmptyEntries);

 

在asp.net 1.1 中,因没有StringSplitOptions.RemoveEmptyEntries参数,想到的只有正则表达式了
 input)
        {
            Regex r = new Regex(@"\b(?<=[\s()-]|^)(?<number>\d+)(?=[\s()-]|$)\b");
            MatchCollection mc 
= r.Matches(input);
            
int count = mc.Count;
            
string[] matches = new string[count];


            
for (int i = 0; i< count; i++)
            {
                matches[i] 
= mc[i].Groups["number"].Value;
            }

            
return matches;

        }

 

对于电话获取前2组就够了

 


        /// 将区号和电话号码分组
        
/// </summary>
        
/// <param name="txtPhoneAreaCode">区号</param>
        
/// <param name="txtPhoneNumber">电话号码</param>
        
/// <param name="input">输入的电话号码</param>
        public static void SetPhoneValue(TextBox txtPhoneAreaCode, TextBox txtPhoneNumber, string input)
        {
            
string[] arrs = GetMatches(input);
            
if (arrs.Length == 0)
            {
                txtPhoneAreaCode.Text 
= string.Empty;
                txtPhoneNumber.Text 
= string.Empty;
            }
            
else if (arrs.Length == 1)
            {
                txtPhoneAreaCode.Text 
= string.Empty;
                txtPhoneNumber.Text 
= arrs[0];
            }
            
else
            {
                txtPhoneAreaCode.Text 
= arrs[0];
                txtPhoneNumber.Text 
= arrs[1];
            }
            
        }

相关文章:

  • 2022-01-08
  • 2022-12-23
  • 2021-12-15
  • 2021-12-15
  • 2021-12-25
  • 2022-02-17
猜你喜欢
  • 2021-12-15
  • 2022-01-04
  • 2021-12-15
  • 2021-12-21
  • 2021-12-23
相关资源
相似解决方案