String类使用的例子(2)

王朝other·作者佚名  2008-05-31
窄屏简体版  字體: |||超大  

Console.Write("Enter the string array length : ");

string strArr=Console.ReadLine();

int intArr=int.Parse(strArr);

for (int i=0;i<intArr;i++) {

Console.Write("Enter string " + i + " : ");

strTempArr[i]=Console.ReadLine();

}

Console.WriteLine("the Concatenated string : " + String.Concat(strTempArr));

Console.WriteLine("the concatenation of the first two string : " + String.Concat(strTempArr[0],strTempArr[1]));

Console.WriteLine("the concatenation of the first three string : " + String.Concat(strTempArr[0],strTempArr[1],strTempArr[2]));

Console.WriteLine("the concatenation of the first four string : " + String.Concat(strTempArr[0],strTempArr[1],strTempArr[2],strTempArr[3]));

}

private void mtdCopy() {

Console.WriteLine("String.Copy(String str) - > returns a new string with the same value as ‘str‘");

Console.WriteLine("original string : " + objString.str);

Console.Write("enter the string to replace the above one : ");

string strCopy=Console.ReadLine();

objString.str=String.Copy(strCopy);

Console.WriteLine("the string after copying : " + objString.str);

}

private void mtdCopyTo() {

Console.WriteLine("String.CopyTo(int srcIndex,char[] dest,int destIndex,int intCount) - > copies a part of string to another string");

Console.WriteLine("srcIndex -> the start index in the original string from where u want the copy");

Console.WriteLine("dest -> the destination chracter array");

Console.WriteLine("destIndex -> the start index in the destination array to which the characters should be copied");

Console.WriteLine("dest -> the length of characters in the original string to be copied");

Console.WriteLine("Destination string is : " + objString.str);

Console.Write("Enter the source string : ");

string strTmp=Console.ReadLine();

Console.Write("Enter the starting index for source string : ");

string strSrcSt=Console.ReadLine();

int intSrcSt=int.Parse(strSrcSt);

Console.Write("Enter the starting index in the destination string : ");

string strDstSt=Console.ReadLine();

int intDstSt=int.Parse(strDstSt);

Console.Write("Enter the number of characters to be copied from the source string : ");

string strSrcLn=Console.ReadLine();

int intSrcLn=int.Parse(strSrcLn);

chArray=objString.str.ToCharArray();

strTmp.CopyTo(intSrcSt,chArray,intDstSt,intSrcLn);

objString.str=new String(chArray);

Console.WriteLine("The changed string is : " + objString.str);

}

private void mtdEndsWith() {

Console.WriteLine("String.EndsWith(String str) - > this function returns a boolen value, checking whether the parent string ends with ‘str‘");

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航