ID #77381

String类使用的例子(2)


  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‘");


2011-09-27 21:18
阅读:
I'm VC , Just U know Y
本站部分文章来源于互联网,版权归原作者所有。

延伸阅读:

myeclipse 8下载和注册码

用Java程序编写记事本

不用spring,hibernate超傻瓜JAVA开发(javabean+数组)

用Java编写计算器的几种常见的做法

页面校验通用js.txt