public classclsArrayList
{public int p_Count = -1; //数据组数
private string[] myArray1; //一维矩阵
private string[,] myArray2; //二维矩阵
///
///一维字符串分隔,初始化.例: clsArrayList myArray1List=new clsArrayList("1;2;3;4;5",';')///
///
///
public clsArrayList(string strStringSource, charcharSepartor)
{try{
myArray1= strStringSource.Split(charSepartor);//截取
p_Count =myArray1.Length;
}catch(Exception ex)
{
clsLogHelper.m_CreateErrorLogTxt("clsArrayList(" + strStringSource + "," + charSepartor + ")", "", ex.Message.ToString());
}
}///
///二维字符串分隔,初始化. 例: clsArrayList myArray1List=new clsArrayList("1,A;2,B;3,C;4,D;5,E" , ';' , ',')///
///
///
///
///
public clsArrayList(string strStringSource, char charColumnSepartor, charcharRowSepartor)
{try{string[] strColumn; //第一次截取 ";"
string[] strRow; //第二次截取 ","
strColumn= strStringSource.Split(charColumnSepartor);//第一次截取
p_Count =strColumn.Length;
myArray2= new string[p_Count, 2];for (int i = 0; i <= p_Count - 1; i++) //将数据保存 数组 myArray1 中
{
strRow= strColumn[i].Split(charRowSepartor);//第二次截取
myArray2[i, 0] = strRow[0];
myArray2[i,1] = strRow[1];
}
}catch(Exception ex)
{
clsLogHelper.m_CreateErrorLogTxt("clsArrayList(" + strStringSource + "," + charColumnSepartor + "," + charRowSepartor + ")", "", ex.Message.ToString());
}
}///
///一维字符串,取值///
///
///
public string m_GetItem(intintIndex)
{if (myArray1 == null)
{return "";
}if (p_Count == -1)
{return "";
}if (intIndex > p_Count - 1)
{return "";
}else{returnmyArray1[intIndex];
}
}///
///二维字符串,取值///
///
///
///
///
public string m_GetItem(int intKeyIndex, intintValueIndex)
{if (myArray2 == null)
{return "";
}if (p_Count == -1)
{return "";
}if (intKeyIndex > p_Count - 1 || intValueIndex > 1)//Value为列,二维
{return "";
}else{returnmyArray2[intKeyIndex, intValueIndex];
}
}///
///二维字符串,通过Value 获取Key ,例: m_GetKey("1")///
///
///
///
public string m_GetKey(stringstrValue)
{try{if (myArray2 == null)
{return "";
}if (p_Count == -1)
{return "";
}for (int i = 0; i <= p_Count - 1; i++) //通过value查找key
{if (myArray2[i, 1] ==strValue)
{return myArray2[i, 0]; //返回key的值
}
}return "";
}catch(Exception ex)
{
clsLogHelper.m_CreateErrorLogTxt("clsArrayList(" + strValue + ")", "", ex.Message.ToString());return "";
}
}///
///二维字符串,通过Key 获取Value///
///
///
///
public string m_GetValue(stringstrKey)
{try{if (myArray2 == null)
{return "";
}if (p_Count == -1)
{return "";
}for (int i = 0; i <= p_Count - 1; i++) //通过key查找value
{if (myArray2[i, 0] ==strKey)
{return myArray2[i, 1]; //返回value的值
}
}return "";
}catch(Exception ex)
{
clsLogHelper.m_CreateErrorLogTxt("m_GetValue(" + strKey + ")", "", ex.Message.ToString());return "";
}
}