hany mohamed

hany mohamed

  • 1.3k
  • 116
  • 4.1k

Can't Serialize And Normalize the Receipt

Jan 1 2025 5:56 PM

I am trying to make Serialize And Normalize using this code 

 public static string SerializeAndNormalizeReceipt(object receipt)
 {
     if (receipt == null)
         return string.Empty;

     string serializedData = JsonConvert.SerializeObject(receipt, Formatting.None);

     string normalizedData = NormalizeText(serializedData);

     return normalizedData;
 }

 public static string NormalizeText(string text)
 {
     if (string.IsNullOrEmpty(text))
         return string.Empty;

     string cleanedText = Regex.Replace(text, @"[:\,]", "");

     string normalizedText = Regex.Replace(cleanedText, @"[a-z]", m => m.Value.ToUpper());

     normalizedText = Regex.Replace(normalizedText, @"[\u0600-\u06FF]+", m => m.Value);

     normalizedText = Regex.Replace(normalizedText, @"[\{\}\[\]]", "");

     normalizedText = Regex.Replace(normalizedText, @"\s+(?=[a-zA-Z0-9])", "");

     return normalizedText;
 }

and i get this output 

"HEADER""DATETIMEISSUED""2024-12-30T173749""RECEIPTNUMBER""HAZ002""UUID""""PREVIOUSUUID""""REFERENCEOLDUUID""""CURRENCY""EGP""EXCHANGERATE"0"DOCUMENTTYPE""RECEIPTTYPE""S""TYPEVERSION""1.2""SELLER""RIN""332460843""COMPANYTRADENAME""???? ???? ???? ???""BRANCHCODE""ABC""DEVICESERIALNUMBER""CWX02618""ACTIVITYCODE""8620""BRANCHADDRESS""COUNTRY""EG""GOVERNATE""CAIRO""REGIONCITY""CITYCENTER""STREET""16STREET""BUILDINGNUMBER""14BN""BUYER""TYPE""F""ID""313717919""NAME""TAXPAYER1""MOBILENUMBER""+201020567462""PAYMENTNUMBER""987654""ITEMDATA""INTERNALCODE""NA""DESCRIPTION""MEDICALCAREFORTHEELDERLY""ITEMTYPE""EGS""ITEMCODE""EG-332460843-M3""UNITTYPE""EA""QUANTITY"1"UNITPRICE"200"NETSALE"200"TOTALSALE"200"TOTAL"200"COMMERCIALDISCOUNTDATA""AMOUNT"0"DESCRIPTION""NODISCOUNT""RATE"0"ITEMDISCOUNTDATA""AMOUNT"0"DESCRIPTION""NODISCOUNT""RATE"0"TAXABLEITEMS""TAXTYPE""T1""AMOUNT"28"SUBTYPE""V009""RATE"14"TOTALSALES"200"TOTALCOMMERCIALDISCOUNT"0"TOTALITEMSDISCOUNT"0"EXTRARECEIPTDISCOUNTDATA""AMOUNT"0"DESCRIPTION""NODISCOUNT""RATE"0"NETAMOUNT"200"FEESAMOUNT"0"TOTALAMOUNT"228"TAXTOTALS""TAXTYPE""T1""AMOUNT"28"PAYMENTMETHOD""C""ADJUSTMENT"0"CONTRACTOR""NAME""CONTRACTOR1""AMOUNT"0"RATE"0  

The problem is that all numerical fields, such as quantity, price, total, etc., I cannot put a quotation mark around their numbers


Answers (7)