How to write sorting in a more efficient way?

I have a project where I have to write efficient code that will work as quickly as possible, but I do not know how to do this, therefore ...

So, I have an asp.net project (MVC) using an entity structure, and I also have to use a web service to get the details information from it. First, I make a request to the web service and respond with a long string, which I must parse in the list of strings for further actions.

I parse this line as follows:

string resultString;
char[] delimiterChars = { ',', ':', '"', '}', '{' };
List<string> words = resultString.Split(delimiterChars).ToList();

From here I have a list with a lot of lines that contain information and many unwanted lines that look like this:

list of lines

, , ifs ..:

for (int i = words.Count - 1; i >= 0; i--)
{
    if (words[i] == "" || words[i] == "data" || words[i] == "array") words.RemoveAt(i);
}

, , , .., ,, , 21,55 , 2 21 55. , , , -, , ,.

, ( , : 1) attrValue 2) 21 3) 55 : 1) attrValue 2) 21.55):

 for (int i = 0; i < words.Count(); i++)
        {
            if (words[i] == "attrValue")
            {
                try
                {
                    var seconPartInt = Int32.Parse(words[i + 2]);
                    words[i + 1] += "." + words[i + 2];
                }
                catch { }
            }
            if (words[i].Contains("\\/")) words[i].Replace("\\/", "/");
        }

, , , 30%. , ...

: , . , , int, , , .

?

+4
1

, , Split, (https://msdn.microsoft.com/en-us/library/ms131448(v=vs.110).aspx).

List<string> words = resultString.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries)
    .ToList();

, , "" "" , , , .

resultString = resultString.Replace("data", String.Empty)
    .Replace("array", String.Empty);

, , , (.. 25,50 ).

+3

Source: https://habr.com/ru/post/1655344/


All Articles