using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IOB_WIN_SIEMENS
{
    /// <summary>
    /// Definizione area memoria SIEMENS
    /// </summary>
    public class memAreaSiemens
    {
        #region Public Fields

        /// <summary>
        /// Indice DB
        /// </summary>
        public int DbNum = 0;

        /// <summary>
        /// Indice partenza memoria (es DBD0 --> 0)
        /// </summary>
        public int indiceMem = 0;

        /// <summary>
        /// Tipo Memoria (DBD, DBW...)
        /// </summary>
        public string tipoMem = "";

        #endregion Public Fields

        #region Public Constructors

        /// <summary>
        /// Inizializza da un formato stringa
        /// </summary>
        /// <param name="strFormat"></param>
        public memAreaSiemens(string strFormat)
        {
            if (!string.IsNullOrEmpty(strFormat))
            {
                string[] memComp = strFormat.Split('.');
                int.TryParse(memComp[0].Replace("DB", ""), out DbNum);
                //tipoMem = memComp[1].Substring(2, 1);
                tipoMem = "";
                for (int i = 0; i < memComp[1].Length; i++)
                {
                    if (char.IsLetter(memComp[1][i]))
                    {
                        tipoMem += memComp[1][i];
                    }
                }
                // rimuovo DB iniziale..
                tipoMem = tipoMem.Replace("DB", "");
                // ciclo x trovare SOLO stringa
                int.TryParse(memComp[1].Replace("DB", "").Replace(tipoMem, ""), out indiceMem);
            }
        }

        #endregion Public Constructors
    }
}
