选择显示字体大小

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

console.writeline("the string to be checked :" + objstring.str);
console.write("enter the 'ends with' string :");
string strtmp = console.readline();
if (objstring.str.endswith(strtmp))
console.writeline("'"+ objstring.str + "' ends with '" + strtmp + "'.");
else
console.writeline("'" + objstring.str + "' does not end with '" + strtmp + "'.");
}

private void mtdformat() {
console.writeline("string.format() - > this static function helps in formating the strings");
console.writeline("format(string str,object obj) -> format the string with one object");
console.writeline("format(string str,object obj1,object obj2) -> format the string with two objects");
console.writeline("formating the string with three objects is another implementation.");
console.writeline("the string should follow the formating specification - > {n,[m]:[formatstring]}");
console.writeline("n -> indicates the argument to be replaced. starts from zero(0)");
console.writeline("m -> indicates the length of formatting area,padded with spaces if the value filled in is smaller.");

console.writeline("if the value is -ve then value is left justified, if value is +ve then value is right justified.");

console.writeline("formatstring -> these are values of formating codes (eg : 'c' is used for currency)");

string strtmp="it is {0} working in {1,10} bcos i get {2,5:c} per month.it is not {0} working {1,-10} bcos i get only {2,-5:c}";

console.writeline("the source string is : " + strtmp);
console.write("enter the first replacement string : ");
string strtmp1=console.readline();
console.write("enter the second replacement string : ");
string strtmp2=console.readline();
console.write("enter a numeral : ");
string strtmp3=console.readline();
int inttmp=int.parse(strtmp3);
console.writeline("the modified string :" + string.format(strtmp,strtmp1,strtmp2,inttmp));
}

private void mtdhash() {
console.writeline("string.gethashcode() - > this fuctions returns the hash code of the string");
console.writeline("hash of '"+ objstring.str + "' is : " + objstring.str.gethashcode());
}

private void mtdindexof() {
console.writeline("string.indexof() - > this returns the index of the first occurence of a charcter or string in the given string.");

console.writeline("the search of the string stops when the required value is founds or proceedes until the end of the string has been reached");

console.writeline("it returns the index if the value is found or '-1' if not found.");
mtdindeximpl("index","first");
}

private void mtdindeximpl(string strvalue,string strfl) {
string strchar;
char c;
int intstart;
int intcount;
console.writeline("1. string."+strvalue+"of(char c) -> returns the "+strfl+" occurence 'c' in the string");

console.writeline("2. string."+strvalue+"of(string str) -> returns the "+strfl+" occurence of 'str' in the string");

console.writeline("3. string."+strvalue+"of(char c,int i) -> returns the "+strfl+" occurence of 'c' in the string, the search starts from 'i'");

console.writeline("4. string."+strvalue+"of(string str,int i) -> returns the "+strfl+" occurence of 'str' in the string, the search starts from 'i'");

console.writeline("5. string."+strvalue+"of(char c,int i,int j) -> returns the "+strfl+" occurence of 'c' in the string, the search starting from 'i' and examining 'j' character positions.");

console.writeline("6. string."+strvalue+"of(string str,int i,int j) -> returns the "+strfl+" occurence of 'str' in the string, the search starting from 'i' and examining 'j' character positions.");

console.writeline("7. finished with "+strvalue+"of.");
console.write("give the choice :");
string strtmp=console.readline();
int intchoice=int.parse(strtmp);
bool blnstay=true;
console.writeline("the source string is :"+objstring.str);
switch (intchoice) {
case 1:
console.write("enter the character :");
strchar=console.readline();
c=(strchar.tochararray())[0];
if ("first"==strfl)
console.writeline("the index of '"+c+"' in '"+objstring.str+"' is : "+objstring.str.indexof(c));

else
console.writeline("the index of '"+c+"' in '"+objstring.str+"' is : "+objstring.str.lastindexof(c));

break;
case 2:
console.write("enter the string :");
strchar=console.readline();
if ("first"==strfl)
console.writeline("the index of '"+strchar+"' in '"+objstring.str+"' is : "+objstring.str.indexof(strchar));

else
console.writeline("the index of '"+strchar+"' in '"+objstring.str+"' is : "+objstring.str.lastindexof(strchar));

break;
case 3:
console.write("enter the character :");
strchar=console.readline();
c=(strchar.tochararray())[0];
console.write("enter the starting index :");
intstart=int.parse(console.readline());
if ("first"==strfl)
console.writeline("the index of '"+c+"' in '"+objstring.str+"' is : "+objstring.str.indexof(c,intstart));

else
console.writeline("the index of '"+c+"' in '"+objstring.str+"' is : "+objstring.str.lastindexof(c,intstart));

break;
case 4:
console.write("enter the string :");
strchar=console.readline();
console.write("enter the starting index :");
intstart=int.parse(console.readline());
if ("first"==strfl)
console.writeline("the index of '"+strchar+"' in '"+objstring.str+"' is : "+objstring.str.indexof(strchar,intstart));

else
console.writeline("the index of '"+strchar+"' in '"+objstring.str+"' is : "+objstring.str.lastindexof(strchar,intstart));

break;
case 5:
console.write("enter the character :");
strchar=console.readline();
c=(strchar.tochararray())[0];
console.write("enter the starting index :");
intstart=int.parse(console.readline());
console.write("enter the number of characters to search : ");
intcount=int.parse(console.readline());
if ("first"==strfl)
console.writeline("the index of '"+c+"' in '"+objstring.str+"' is : "+objstring.str.indexof(c,intstart,intcount));

else
console.writeline("the index of '"+c+"' in '"+objstring.str+"' is : "+objstring.str.lastindexof(c,intstart,intcount));

break;
case 6:
console.write("enter the character :");
strchar=console.readline();
console.write("enter the starting index :");
intstart=int.parse(console.readline());
console.write("enter the number of characters to search : ");
intcount=int.parse(console.readline());
if ("first"==strfl)
console.writeline("the index of '"+strchar+"' in '"+objstring.str+"' is : "+objstring.str.indexof(strchar,intstart,intcount));

else
console.writeline("the index of '"+strchar+"' in '"+objstring.str+"' is : "+objstring.str.lastindexof(strchar,intstart,intcount));

break;
case 7:
blnstay=false;
break;
}
if (blnstay)
mtdindeximpl(strvalue,strfl);
}

private void mtdindexofany() {
console.writeline("string.indexofany() - > this returns the index of the first occurence of any charcter of the character array in the given string.");

console.writeline("the search of the string stops when the required value is founds or proceedes until the end of the string has been reached");

console.writeline("it returns the index if the value is found or '-1' if not found.");
mtdindexanyimpl("index","first");
}

private void mtdindexanyimpl(string strvalue,string strfl) {
string strchar;
char[] c=new char[char.maxvalue];
int intstart;
int intcount;
console.writeline("1. string."+strvalue+"ofany(char[] c) -> returns the "+strfl+" occurence of any character of the array in the string");

console.writeline("2. string."+strvalue+"ofany(char[] c,int i) -> returns the "+strfl+" occurence of any character of the array in the string, the search starts from 'i'");

console.writeline("3. string."+strvalue+"of(char[] c,int i,int j) -> returns the "+strfl+" occurence of any character of the array in the string, the search starting from 'i' and examining 'j' character positions.");

console.writeline("4. finished with "+strvalue+"ofany.");
console.write("give the choice :");
string strtmp=console.readline();
int intchoice=int.parse(strtmp);
bool blnstay=true;
console.writeline("the source string is : "+objstring.str );
switch (intchoice) {
case 1:
console.write("enter the string for the character array :");
strchar=console.readline();
c=strchar.tochararray();
if ("first"==strfl)
console.writeline("the index value returned is : "+ objstring.str.indexofany(c));

else
console.writeline("the index value returned is : "+ objstring.str.lastindexofany(c));

break;
case 2:
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());

  


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons