2017-10-18 26 views
1

我正在设计一个库存系统,我应该在每次销售产品时更新库存。我的股票列看起来如下:在ms访问中扣除和更新字母数字字符串

股票 350 MTS 500个 750 MTS 1000 MTS

现在我的要求可分为两个部分,

  1. 我怎么减去这个数字字母从销售数量的字符串,
  2. 而更新单位也应该出现在DB与数字。

任何帮助将高度赞赏

+0

你为什么要这样存储它?将单位分别储存到计数中会不会更容易? – john

+1

非常感谢John的投入对我的帮助确实有所帮助,直到你提到它,它才引起我的注意。再次感谢 – Ashiq

回答

0

使用正则表达式这一点。

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Text.RegularExpressions; 

namespace ConsoleApplication1 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      string input = "Stock 350 mts 500 pcs 750 mts 1000 mts"; 
      // any word characters followed by any white spaces 
      // followed by any number of digits 
      string pattern = @"(?'name'\w+)\s+(?'quantity'\d+)"; 

      MatchCollection matches = Regex.Matches(input, pattern); 

      foreach (Match match in matches) 
      { 
       Console.WriteLine("Name : '{0}', Qnty : '{1}'", match.Groups["name"].Value, match.Groups["quantity"].Value); 
      } 
      Console.ReadLine(); 
     } 
    } 
}