C#课程设计 字符串类的设计 定义一个字符串(string)类,包含存放在字符串的字符数组和字符串中

字符串类的设计
定义一个字符串(string)类,包含存放在字符串的字符数组和字符串中字符的个数。
字符串的输入与赋值;
字符串的运算包括:连接,复制,查找,交换,比较
字符串的输出

这是Replace(替换)方法,你仿照它写其它方法把
[ThreadStatic]
static char[] mTempChars;
protected static char[] GetTempData()
{
if (mTempChars == null)
mTempChars = new char[1024 * 64];
return mTempChars;
}
public static string Replace(string value, string oldData, string newData)
{
char[] tmpchars = GetTempData();
int newpostion = 0;
int oldpostion = 0;
int length = value.Length;
int oldlength = oldData.Length;
int newlength = newData.Length;
int index = 0;
int copylength = 0;
bool eq = false;
while (index < value.Length)
{
eq = true;
for (int k = 0; k < oldlength; k++)
{
if (value[index + k] != oldData[k])
{
eq = false;
break;
}
}
if (eq)
{
copylength = index - oldpostion;
value.CopyTo(oldpostion, tmpchars, newpostion, copylength);
newpostion += copylength;
index += oldlength;
oldpostion = index;
newData.CopyTo(0, tmpchars, newpostion, newlength);
newpostion += newlength;
}
else
{
index++;
}
}
if (oldpostion < length)
{
copylength = index - oldpostion;
value.CopyTo(oldpostion, tmpchars, newpostion, copylength);
newpostion += copylength;
}
return new string(tmpchars, 0, newpostion);
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-12-03
能说具体点吗?都不知道你表达的意思是什么追问

写程序

第2个回答  2014-12-03
需要帮你做吗追问

需要

追答

丘说吧
我id

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网