C# 指定格式的字符串截成一维数组(二维数组)的操作类
2011-08-15 12:52
721 查看
using System;
using System.Text;
namespace myClass
{
class clsArrayList
{
public
int p_Count=-1;
//数据组数
private string[] myArray1;
//一维矩阵
private string[,] myArray2;
//二维矩阵
///
<summary>
/// 一维字符串分隔,初始化.例: clsArrayList myArray1List=new clsArrayList("1;2;3;4;5",';')
///
</summary>
///
<param name="strStringSource"></param>
///
<remarks>gx 2010-04-25</remarks>
public clsArrayList(string strStringSource,
char charSepartor)
{
try
{
myArray1 = strStringSource.Split(charSepartor);//截取
p_Count
= myArray1.Length;
}
catch(Exception ex)
{
myClass.clsLogHelper.m_CreateErrorLogTxt("clsArrayList("
+ strStringSource
+ " ,
" + charSepartor
+ ")",
"", ex.Message.ToString());
}
}
///
<summary>
/// 二维字符串分隔,初始化. 例: clsArrayList myArray1List=new clsArrayList("1,A;2,B;3,C;4,D;5,E"
, ';' , ',')
///
</summary>
///
<param name="strStringSource"></param>
///
<param name="strColumnSepartor"></param>
///
<param name="strRowSepartor"></param>
///
<remarks>gx 2010-04-25</remarks>
public clsArrayList(string strStringSource,
char charColumnSepartor,
char charRowSepartor)
{
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)
{
myClass.clsLogHelper.m_CreateErrorLogTxt("clsArrayList("
+ strStringSource
+ " ,
" + charColumnSepartor
+ " ,
" + charRowSepartor
+ ")",
"", ex.Message.ToString());
}
}
///
<summary>
/// 一维字符串,取值
///
</summary>
///
<param name="intIndex"></param>
///
<returns></returns>
public string m_GetItem(int
intIndex)
{
if (myArray1
== null)
{
return
"";
}
if (p_Count
== -
1)
{
return
"";
}
if (intIndex
> p_Count
- 1)
{
return
"";
}
else
{
return myArray1[intIndex];
}
}
///
<summary>
/// 二维字符串,取值
///
</summary>
///
<param name="intKeyIndex"></param>
///
<param name="intValueIndex"></param>
///
<returns></returns>
///
<remarks>gx 2010-04-25</remarks>
public string m_GetItem(int intKeyIndex,int
intValueIndex)
{
if (myArray2
== null)
{
return
"";
}
if (p_Count
== -1)
{
return
"";
}
if (intKeyIndex
> p_Count
- 1
|| intValueIndex
> 1)//Value为列,二维
{
return
"";
}
else
{
return myArray2[intKeyIndex, intValueIndex];
}
}
///
<summary>
/// 二维字符串,通过Value 获取Key ,例: m_GetKey("1")
///
</summary>
///
<param name="strValue"></param>
///
<returns></returns>
///
<remarks>gx 2010-04-25</remarks>
public string m_GetKey(string
strValue)
{
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)
{
myClass.clsLogHelper.m_CreateErrorLogTxt("clsArrayList("
+ strValue
+ ")",
"", ex.Message.ToString());
return
"";
}
}
///
<summary>
/// 二维字符串,通过Key 获取Value
///
</summary>
///
<param name="strKey"></param>
///
<returns></returns>
///
<remarks>gx 2010-04-25</remarks>
public string m_GetValue(string
strKey)
{
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)
{
myClass.clsLogHelper.m_CreateErrorLogTxt("m_GetValue("
+ strKey
+ ")",
"", ex.Message.ToString());
return
"";
}
}
}
}
using System.Text;
namespace myClass
{
class clsArrayList
{
public
int p_Count=-1;
//数据组数
private string[] myArray1;
//一维矩阵
private string[,] myArray2;
//二维矩阵
///
<summary>
/// 一维字符串分隔,初始化.例: clsArrayList myArray1List=new clsArrayList("1;2;3;4;5",';')
///
</summary>
///
<param name="strStringSource"></param>
///
<remarks>gx 2010-04-25</remarks>
public clsArrayList(string strStringSource,
char charSepartor)
{
try
{
myArray1 = strStringSource.Split(charSepartor);//截取
p_Count
= myArray1.Length;
}
catch(Exception ex)
{
myClass.clsLogHelper.m_CreateErrorLogTxt("clsArrayList("
+ strStringSource
+ " ,
" + charSepartor
+ ")",
"", ex.Message.ToString());
}
}
///
<summary>
/// 二维字符串分隔,初始化. 例: clsArrayList myArray1List=new clsArrayList("1,A;2,B;3,C;4,D;5,E"
, ';' , ',')
///
</summary>
///
<param name="strStringSource"></param>
///
<param name="strColumnSepartor"></param>
///
<param name="strRowSepartor"></param>
///
<remarks>gx 2010-04-25</remarks>
public clsArrayList(string strStringSource,
char charColumnSepartor,
char charRowSepartor)
{
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)
{
myClass.clsLogHelper.m_CreateErrorLogTxt("clsArrayList("
+ strStringSource
+ " ,
" + charColumnSepartor
+ " ,
" + charRowSepartor
+ ")",
"", ex.Message.ToString());
}
}
///
<summary>
/// 一维字符串,取值
///
</summary>
///
<param name="intIndex"></param>
///
<returns></returns>
public string m_GetItem(int
intIndex)
{
if (myArray1
== null)
{
return
"";
}
if (p_Count
== -
1)
{
return
"";
}
if (intIndex
> p_Count
- 1)
{
return
"";
}
else
{
return myArray1[intIndex];
}
}
///
<summary>
/// 二维字符串,取值
///
</summary>
///
<param name="intKeyIndex"></param>
///
<param name="intValueIndex"></param>
///
<returns></returns>
///
<remarks>gx 2010-04-25</remarks>
public string m_GetItem(int intKeyIndex,int
intValueIndex)
{
if (myArray2
== null)
{
return
"";
}
if (p_Count
== -1)
{
return
"";
}
if (intKeyIndex
> p_Count
- 1
|| intValueIndex
> 1)//Value为列,二维
{
return
"";
}
else
{
return myArray2[intKeyIndex, intValueIndex];
}
}
///
<summary>
/// 二维字符串,通过Value 获取Key ,例: m_GetKey("1")
///
</summary>
///
<param name="strValue"></param>
///
<returns></returns>
///
<remarks>gx 2010-04-25</remarks>
public string m_GetKey(string
strValue)
{
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)
{
myClass.clsLogHelper.m_CreateErrorLogTxt("clsArrayList("
+ strValue
+ ")",
"", ex.Message.ToString());
return
"";
}
}
///
<summary>
/// 二维字符串,通过Key 获取Value
///
</summary>
///
<param name="strKey"></param>
///
<returns></returns>
///
<remarks>gx 2010-04-25</remarks>
public string m_GetValue(string
strKey)
{
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)
{
myClass.clsLogHelper.m_CreateErrorLogTxt("m_GetValue("
+ strKey
+ ")",
"", ex.Message.ToString());
return
"";
}
}
}
}
相关文章推荐
- C# 指定格式的字符串截成一维数组(二维数组)的操作类
- 一维数组,字符数组,字符串,二维数组在sizeof()和strlen()下的不同输出
- 二维数组,锯齿数组和集合 C# 一维数组、二维数组(矩形数组)、交错数组(锯齿数组)的使用 C# 数组、多维数组(矩形数组)、锯齿数组(交叉数组)
- Java基础知识强化44:StringBuffer类之把数组拼接成指定格式的字符串的案例
- 字符串分割成一维数组、二维数组,一维数组与二维数组之间的转换
- 关于算法—— 一维字符串数组之间组合问题的C#实现
- C#控制台基础 字节数组转UTF8格式的字符串
- 常见对象-把数组拼接成指定格式的字符串案例
- C#调用C++ 平台调用P/Invoke 结构体--含有内置数据类型的一维、二维数组、字符串指针【六】
- 把数组按指定的格式拼接成一个字符串
- 二级联动;字符串转一维数组,一维数组转二维数,二维数组转DataSet
- 数组和字符串操作(C#) 1、从字符串中删除指定字符
- c#中将【对象转成 JSON 格式的字符串】 及获取Json格式字符串并将转成Json对象 及对js数组取数据
- C# 数组、一维数组、二维数组、多维数组、锯齿数组
- 程序员面试指南(第六章) 数组和字符串(C#版) 2.从字符串中删除指定的字符
- C#控制台基础 检测一个string数组是否包含指定的string字符串
- 合并并且排序指针数组和二维数组里面存放的字符串用函数调用的格式
- 常见对象_把数组拼接成指定格式的字符串案例
- (转)一维字符串数组之间组合问题的C#实现
- 练习LINQ:同时操作二维和一维数组,把二维数组转为一维,计算一维和二维值,字符串组合,计算数组和,数组筛选,排序