Rakib Ahmed

Rakib Ahmed

  • NA
  • 61
  • 5.5k

String Split from one line text

Jul 8 2020 5:40 AM
I have a string like
String OrderText = @"1 MI-SCBSMT24SM 10 45.62 1 PC 456.20 2020.03.18
MI-SCBSMT24SM,, MI-SCBSMT24SM
2 MI-SCBSML24SM 10 32.28 1 PC 322.80 2020.03.18
MI-SCBSML24SM,, MI-SCBSML24SM"
 
Here one order is 1 MI-SCBSMT24SM 10 45.62 1 PC 456.20 2020.03.18 MI-SCBSMT24SM,, MI-SCBSMT24SM
 
And second order is
 
2 MI-SCBSML24SM 10 32.28 1 PC 322.80 2020.03.18 MI-SCBSML24SM,, MI-SCBSML24SM
 
It can be consist of 3 rows
 
what i wanted to do split by each of order
 
my output will be like
  1. orderRow.ArticleCode = OrderItem[1]; // MI-SCBSMT24SM  
  2. orderRow.Quantity = Convert.ToInt32(OrderItem[2]); // 10  
  3. orderRow.Price = OrderItem[3]; // 45.62  
  4. orderRow.Amount = OrderItem[6]; // 456.20  
  5. orderRow.DeliveryDate = OrderItem[7].Replace(".""-"); // 2020.03.18  
and for second orderrow
  1. orderRow.ArticleCode = OrderItem[1]; // MI-SCBSML24SM  
  2. orderRow.Quantity = Convert.ToInt32(OrderItem[2]); // 10  
  3. orderRow.Price = OrderItem[3]; // 32.28  
  4. orderRow.Amount = OrderItem[6]; // 322.80  
  5. orderRow.DeliveryDate = OrderItem[7].Replace(".""-"); // 2020.03.18  
3rd row i mean that there can be another row like below way
 
3 MI-SCBSML24SM 10 32.28 1 PC 322.80 2020.03.18
MI-SCBSML24SM,, MI-SCBSML24SM
 
we have to do the same
  1. orderRow.ArticleCode = OrderItem[1]; // MI-SCBSML24SM  
  2. orderRow.Quantity = Convert.ToInt32(OrderItem[2]); // 10  
  3. orderRow.Price = OrderItem[3]; // 32.28  
  4. orderRow.Amount = OrderItem[6]; // 322.80  
  5. orderRow.DeliveryDate = OrderItem[7].Replace(".""-"); // 2020.03.18  

Answers (3)