String类使用的例子(2)
2008-01-05 08:36:50 来源:WEB开发网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‘");
- ››使用脚本恢复WinXP系统的用户登录密码
- ››使用phpMyadmin创建数据库及独立数据库帐号
- ››使用Zend Framework框架中的Zend_Mail模块发送邮件...
- ››使用cout标准输出如何控制小数点后位数
- ››使用nofollow标签做SEO的技巧
- ››使用 WebSphere Message Broker 的 WebSphere Tra...
- ››使用SQL Server事件探查器做应用程序的性能分析
- ››使用SQL Server事件探查器分析死锁原因
- ››使用纯文本文件打造WCF服务
- ››使用 Dojo 开发定制 Business Space 小部件,第 4...
- ››使用 ADDRESS 与 INDIRECT函数查询信息
- ››使用 COLUMN函数编制单元信息
赞助商链接