Home > Net >  C # if extract string in accordance with the requirements specified in the data items
C # if extract string in accordance with the requirements specified in the data items

Time:10-09

The string is as follows:
Store: * * * * * * * * * * * * shops
Trading hours: the 2016-05-28 16:47:25
Shop assistant: cashier: zhang
Way to trade: sales memo number: 6 u4452800015
Customer number: 2100 9156
* * * * *Mobile phone number: 186 * * * * 6500
System reference number: 000628550564
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - shopping details -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Quantity means the unit price discount amount
16214503133311 1 1 658 100% 658.00
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - payment -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Total amount in total: 1:658.00
Credit card: 658
Store: * * * * * * * * * * * * shops
Trading hours: the 2016-05-28 16:47:25
Shop assistant: cashier: zhang
Way to trade: sales memo number: 6 u4452800016
Customer number: 2100 9156
* * * * *Mobile phone number: 186 * * * * 6500
System reference number: 000628550564
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - shopping details -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Quantity means the unit price discount amount
216214503133311 1 1 429 100% 429.00
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - payment -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Total amount in total: 1:429.00
Credit card: 429
Store: * * * * * * * * * * * * shops
Trading hours: the 2016-05-28 16:47:25
Shop assistant: cashier: zhang
Way to trade: sales memo number: 6 u4452800017
Customer number: 2100 9156
* * * * *Mobile phone number: 186 * * * * 6500
System reference number: 000628550564
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - shopping details -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Quantity means the unit price discount amount
216214503133311 1 1 958 100% 958.00
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - payment -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Total amount in total: 1:958.00
Credit card: 958




Needs to be as string, extraction/document no. : 12 characters behind, at the same time need to extract total compensation: behind the amount of the item, to convert the string into the following three records:
6 u4452800015 658.00
6 u4452800016 429.00
6 u4452800017 958.00
C # should be how to implement ah, thank you!

CodePudding user response:

Operating file in c #, each line, to capture again

CodePudding user response:

 
String test=@ "store: * * * * * * * * * * * * shops
Trading hours: the 2016-05-28 16:47:25
Shop assistant: cashier: zhang
Way to trade: sales memo number: 6 u4452800015
Customer number: 2100 9156
* * * * *Mobile phone number: 186 * * * * 6500
System reference number: 000628550564
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - shopping details -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Quantity means the unit price discount amount
16214503133311 1 1 658 100% 658.00
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - payment -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Total amount in total: 1:658.00
Credit card: 658
Store: * * * * * * * * * * * * shops
Trading hours: the 2016-05-28 16:47:25
Shop assistant: cashier: zhang
Way to trade: sales memo number: 6 u4452800016
Customer number: 2100 9156
* * * * *Mobile phone number: 186 * * * * 6500
System reference number: 000628550564
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - shopping details -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Quantity means the unit price discount amount
216214503133311 1 1 429 100% 429.00
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - payment -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Total amount in total: 1:429.00
Credit card: 429
Store: * * * * * * * * * * * * shops
Trading hours: the 2016-05-28 16:47:25
Shop assistant: cashier: zhang
Way to trade: sales memo number: 6 u4452800017
Customer number: 2100 9156
* * * * *Mobile phone number: 186 * * * * 6500
System reference number: 000628550564
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - shopping details -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Quantity means the unit price discount amount
216214503133311 1 1 958 100% 958.00
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - payment -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Total amount in total: 1:958.00
Credit card: 958 ";
The Regex regOrder=new Regex (" document no. : (. +) ");
MatchCollection matchOrder=regOrder. Matches (test);
Regex regMoney=new Regex (total amount: "(. +)");
MatchCollection matchMoney=regMoney. Matches (test);
StringBuilder sb=new StringBuilder();
MessageBox. Show (matchOrder. Count. The ToString () + matchMoney. Count. The ToString ());
for (int i=0; I & lt; MatchOrder. Count; I++)
{
Sb. Append (matchOrder [I] Groups [1]. The Value. The TrimEnd ());
Sb. Append (" ");
Sb. Append (matchMoney [I] Groups. [1] Value);
}
Enclosing richTextBox1. Text=sb. ToString ();

CodePudding user response:

 string TXT=@ "the original poster published in 2016-05-31 12:30:55 
String intercept string as follows:
Store: * * * * * * * * * * * * shops
Trading hours: the 2016-05-28 16:47:25
Shop assistant: cashier: zhang
Way to trade: sales memo number: 6 u4452800015
Customer number: 2100 9156
* * * * *Mobile phone number: 186 * * * * 6500
System reference number: 000628550564
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - shopping details -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Quantity means the unit price discount amount
16214503133311 1 1 658 100% 658.00
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - payment -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Total amount in total: 1:658.00
Credit card: 658
Store: * * * * * * * * * * * * shops
Trading hours: the 2016-05-28 16:47:25
Shop assistant: cashier: zhang
Way to trade: sales memo number: 6 u4452800016
Customer number: 2100 9156
* * * * *Mobile phone number: 186 * * * * 6500
System reference number: 000628550564
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - shopping details -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Quantity means the unit price discount amount
216214503133311 1 1 429 100% 429.00
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - payment -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Total amount in total: 1:429.00
Credit card: 429
Store: * * * * * * * * * * * * shops
Trading hours: the 2016-05-28 16:47:25
Shop assistant: cashier: zhang
Way to trade: sales memo number: 6 u4452800017
Customer number: 2100 9156
* * * * *Mobile phone number: 186 * * * * 6500
System reference number: 000628550564
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - shopping details -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Quantity means the unit price discount amount
216214503133311 1 1 958 100% 958.00
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - payment -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Total amount in total: 1:958.00
Credit card: 958 ";
The string pattern=@ "(? <=documents \ s * : \ s *) ([^ \ n \ r] *) [\ s \ s] *? Total amount \ s * : \ s * ([^ \ n \ r] *) ";
Foreach (Match m in the Regex Matches (TXT, pattern))
{
Console. WriteLine (" : the total amount of document no. : {0} {1} ", m.G roups. [1] Value, m.G roups. [2] Value);
}

CodePudding user response:

M.G roups [1]. The Value, m.G roups. [2] Value);
How to continue to extract the values in the groups? For example I want to use the second value in this group?nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#
  • Related