String类使用的例子(3)
2008-01-05 08:35:57 来源:WEB开发网if ("first"==strFL)
Console.WriteLine("The index value returned is : "+ objString.str.IndexOfAny(c,intStart));
else
Console.WriteLine("The index value returned is : "+ objString.str.LastIndexOfAny(c,intStart));
break;
case 3:
Console.Write("Enter the string for the character array :");
strChar=Console.ReadLine();
c=strChar.ToCharArray();
Console.Write("Enter the starting Index for search :");
intStart=int.Parse(Console.ReadLine());
Console.Write("Enter the number of characters to searc :");
intCount=int.Parse(Console.ReadLine());
if ("first"==strFL)
Console.WriteLine("The index value returned is : "+ objString.str.IndexOfAny(c,intStart,intCount));
else
Console.WriteLine("The index value returned is : "+ objString.str.LastIndexOfAny(c,intStart,intCount));
break;
case 4:
blnStay=false;
break;
}
if (blnStay)
mtdIndexAnyImpl(strValue,strFL);
}
PRivate void mtdInsert() {
Console.WriteLine("String.Insert(int index,string str) - > this functions returns the original string with ‘str‘ inserted at ‘index‘");
Console.WriteLine("the original string : " + objString.str);
Console.Write("Enter the string to be inserted : ");
string strTmp=Console.ReadLine();
Console.Write("Enter the position where it has to be inserted :");
int intTmp=int.Parse(Console.ReadLine());
objString.str=objString.str.Insert(intTmp,strTmp);
Console.WriteLine("the modified string : " + objString.str);
}
private void mtdJoin() {
string[] s=;
Console.WriteLine("1.String.Join(string str,string[] strarr) - > this functions joins the string arrays using ‘str‘");
Console.WriteLine("2.String.Join(string str,string[] strarr,int i,int j) - > this functions joins the string arrays using ‘str‘ starting from the ‘i‘ th array element and ‘j‘ number of elements after it. ");
Console.Write("Enter your choice :");
string strChoice=Console.ReadLine();
if ("1"==strChoice) {
Console.WriteLine("The string array is :str[0]=‘welcome‘,str[1]=‘to‘,str[2]=‘the‘,str[3]=‘world‘,str[4]=‘of‘,str[5]=‘c#‘");
Console.Write("Enter the string with which to join : ");
string strTmp=Console.ReadLine();
Console.WriteLine("The joint string is : " + String.Join(strTmp,s));
}
else {
Console.WriteLine("The string array is :str[0]=‘welcome‘,str[1]=‘to‘,str[2]=‘the‘,str[3]=‘world‘,str[4]=‘of‘,str[5]=‘c#‘");
Console.Write("Enter the string with which to join : ");
string strTmp=Console.ReadLine();
Console.Write("Enter the starting index of the array : ");
int intStart=int.Parse(Console.ReadLine());
Console.Write("Enter the number of elements to join :" );
int intCount=int.Parse(Console.ReadLine());
Console.WriteLine("The joint string is : " + String.Join(strTmp,s,intStart,intCount));
赞助商链接