c # – Data transfer task

You will be given several lines of messages that contain data. Do you have
To check the validity of the lines. A valid line must be in the
Format: "" s: {sender}; r: {receiver}; m - "{message}"

  • sender – could contain any ASCII character except for ;
  • receiver – could contain any ASCII character except for ;
  • message – It must contain only letters and spaces.

In each valid message there is a hidden size of data transfer. the
The size of the data transfer is calculated by the sum of all the digits in
The names of the sender and the recipient. After each valid message, print a
line in the format: "{senderName} says" {currentMessage} "a
{recieverName} "
. Printed names must contain only letters and
spaces

Example: sender "P @ e $ 5sh # or Go ^ 4sh5ov" is valid and matches, but when
by printing his name, we only print "Pesho Goshov". At the end, print a
line in the format "Total data transferred: {totalData} MB".

using the system;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
class program
{
MessageInfo class
{
public bool isOk = true;
public int messageSize;
chain transmitter
reciver rope;
public chain broadcaster
{
obtain
{
return Regex.Replace (sender, @ " s +", "");
}
set
{
StringBuilder temp = new StringBuilder ();
foreach (var c in value)
{
yes (Char.IsDigit (c))
{
messageSize + = (c - & # 39; 0 & # 39;);
}
if (Char.IsLetter (c) || ​​Char.IsWhiteSpace (c))
{
temp.Append (c);
}
}
sender = temp.ToString ();
}
}
public chain Reciver
{
obtain
{
return Regex.Replace (reciver, @ " s +", "");
}
set
{
StringBuilder temp = new StringBuilder ();
foreach (var c in value)
{
yes (Char.IsDigit (c))
{
messageSize + = (c - & # 39; 0 & # 39;);
}
if (Char.IsLetter (c) || ​​Char.IsWhiteSpace (c))
{
temp.Append (c);
}
}
reciver = temp.ToString ();
}
}
Public string message {get; set; }

}
static empty main ()
{
int n = int.Parse (Console.ReadLine ());
int totalMessageSize = 0;
MessageInfo[] chatLog = new MessageInfo[n];
for (int i = 0; i <n; i ++)
{
string line = Console.ReadLine ();
chatLog[i] = CoreAction (line);
yes[i].isOk)
{
totalMessageSize + = chatLog[i].messageSize;
}
}
for (int i = 0; i < chatLog.Length; i++)
        {
            if (chatLog[i].isOk)
            {
                Console.WriteLine("{0} says "{1}" to {2}", chatLog[i].Sender, chatLog[i].Message, chatLog[i].Reciver);
            }
        }
        Console.WriteLine("Total data transferred: {0}MB",totalMessageSize);
    }

    private static MessageInfo CoreAction(string line1)
    {
        MessageInfo a = new MessageInfo();
        int indexer = 0;
        StringBuilder sender = new StringBuilder();
        StringBuilder reciver = new StringBuilder();
        StringBuilder message = new StringBuilder();
        Regex matchLine = new Regex("^s:[^;]+;r:[^;]+;m--"[\w\s]+"$");
        if (matchLine.IsMatch(line1))
        {
            lineSplitter(line1, ref indexer, ref sender, ref reciver, ref message);
        }
        else
        {
            a.isOk = false;
        }
        a.Sender = sender.ToString();
        a.Reciver = reciver.ToString();
        a.Message = message.ToString();
        return a;
    }

    private static void lineSplitter(string line1, ref int indexer, ref StringBuilder sender, ref StringBuilder reciver, ref StringBuilder message)
    {
        while (true)
        {
            if (line1[indexer + 1] == ':')
            {
                if (line1[indexer] == 's')
                {
                    sender = stringFill(line1, ref indexer, 2, ';');
                }
                if (line1[indexer] == 'r')
                {
                    reciver = stringFill(line1, ref indexer, 2, ';');
                }
            }
            if (line1[indexer] == 'm' && line1[indexer + 1] == '-' &&
                line1[indexer + 2] == '-' && line1[indexer + 3] == '"')
            {
                message = stringFill(line1, ref indexer, 4, '"');
            }
            if (indexer >= line1.Length - 1)
{
break;
}
Indexer ++;
}
}

StringBuilder static private stringFill (string line1, ref int indexer, int offSet, char charBreak)
{
StringBuilder temp = new StringBuilder ();
indexer + = offSet;
while (line 1[indexer] ! = charBreak)
{
temp.Append (line1[indexer]);
Indexer ++;
}
return temperature
}
}