Exemplo n.º 1
0
        static string parseAndReplaceStringByHashMap(string originalStr, Char delimiter, MatrixCoordinateMap replaceMap1, MatrixCoordinateMap replaceMap2)
        {
            ConcurrentDictionary <string, string> hashMap1 = replaceMap1.getHashMap();
            ConcurrentDictionary <string, string> hashMap2 = replaceMap2.getHashMap();

            StringBuilder buffer = new StringBuilder();

            char[]   charSeparators = new char[] { delimiter };
            string[] tokens         = originalStr.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries);
            int      length         = tokens.Length;

            string value1 = hashMap1[tokens[0].Trim()];

            if (value1 != null)
            {
                tokens[0] = value1;
            }

            if (length > 1)
            {
                string value2 = hashMap2[tokens[1].Trim()];
                if (value2 != null)
                {
                    tokens[1] = value2;
                }
            }

            for (int i = 0; i < length; i++)
            {
                if (i == 0)
                {
                    buffer.Append(tokens[i].Trim());
                }
                else
                {
                    buffer.Append(delimiter);
                    buffer.Append(tokens[i].Trim());
                }
            }

            string updatedStr = buffer.ToString();

            return(updatedStr);
        }