首 页 网络编程
网页制作 图形图象 操作系统 冲浪宝典
软件教学 认证考试

网络安全 网络办公 行业资讯 评测对比
您当前位置:站长天空 -> 网络编程-> C#/CSHARP教程
String类使用的例子(3)-.NET教程,C#语言
作者:网友供稿 点击:104
推荐
西部数码-全国虚拟主机10强!20余项虚拟主机管理功能,全国领先!第6代双线路虚拟主机,南北访问畅通无阻!可在线rar解压,自动数据恢复设置虚拟目录等.免费赠送访问统计,企业邮局.Cn域名注册10元/年,自助建站480元起,免费试用7天,满意再付款!P4主机租用799元/月.月付免压金
站内搜索
文章页数:[1] 
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={"welcome","to","the","world","of","c#"};
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));

}
}

private void mtdlastindex() {
console.writeline("string.lastindexof() - > this returns the index of the last 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 beginning of the string has been reached");

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

}

private void mtdlastindexany() {
console.writeline("string.lastindexofany() - > this returns the index of the last 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 beginning of the string has been reached");

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

private void mtdlength() {
console.writeline("string.length - > this property returns the length of the string.");
console.writeline("the length of "+objstring.str+" is : "+objstring.str.length);
}

private void mtdpadleft() {
mtdpad("left");
}

private void mtdpad(string strval) {
console.writeline("string.pad"+strval+"() - > this method pads spaces or some other character to the "+strval+" of the string");

console.writeline("string.pad"+strval+"(int i) -> fills spaces to the "+strval+" of the string, i specifies the length of the string along with spaces");

console.writeline("string.pad"+strval+"(int i,char c) -> fills the character c to the "+strval+" of the string, i specifies the length of the string along with spaces");

console.writeline("the original string :"+objstring.str );
console.write("enter the length of the desired string : ");
int intstart=int.parse(console.readline());
console.write("enter the character to be padded(enter nothing for spaces) :");
string strtmp=console.readline();
if(!strtmp.equals("")) {
char c=(strtmp.tochararray())[0];
if ("left"==strval)
console.writeline("the padded string : " + objstring.str.padleft(intstart,c));
else
console.writeline("the padded string : " + objstring.str.padright(intstart,c));
}
else
if ("left"==strval)
console.writeline("the padded string : " + objstring.str.padleft(intstart));
else
console.writeline("the padded string : " + objstring.str.padright(intstart));

}

private void mtdpadright() {
mtdpad("right");
}

private void mtdremove() {
console.writeline("string.remove(int i,int j) - > removes a part of the string.i represents the start position and j represents the length of string to be removed.");

console.writeline("the original string : "+objstring.str);
console.write("enter the starting position : ");
int intstart=int.parse(console.readline());
console.write("enter the length of string to be removed :");
int intlength=int.parse(console.readline());
console.writeline("the string after removal :"+objstring.str.remove(intstart,intlength));
}

private void mtdreplace() {
console.writeline("string.replace() - > replaces a character with another character or a string with another string throughout the given string");

console.writeline("1. string.replace(char cold,char cnew) -> replaces all occurances cold with cnew");

console.writeline("2. string.replace(string sold,strin snew) -> replaces all occurances of sold with snew");

console.write("enter your choice :");
int intchoice=int.parse(console.readline());
console.writeline("the original string is :"+objstring.str);
if (1==intchoice) {
console.write("enter the character to be replaced :");
char cold=(console.readline().tochararray())[0];
console.write("enter the new character :");
char cnew=(console.readline().tochararray())[0];
console.writeline("the string after replacing : "+objstring.str.replace(cold,cnew));
}
else {
console.write("enter the string to be replaced :");
string sold=console.readline();
console.write("enter the new string :");
string snew=console.readline();
console.writeline("the string after replacing : "+objstring.str.replace(sold,snew));

}
}

private void mtdsplit() {
console.writeline("this will be done later.");
}

private void mtdstartswith() {
console.writeline("string.startswith(string str) - > returns a boolean value indicating whether the string starts with str");

console.writeline("the original string : "+ objstring.str);
console.write("enter the string to search for :");
string strtmp=console.readline();
if (objstring.str.startswith(strtmp))
console.writeline("the string "+objstring.str+" starts with "+strtmp+".");
else
console.writeline("the string "+objstring.str+" does not starts with "+strtmp+".");
}

private void mtdsubstr() {
console.writeline("string.substring() - > retrieves a part of the string from the original string");
console.writeline("1. string.substring(int i) -> retrieves the string starting from i(zero based)");
console.writeline("2. string.substring(int i,int j) -> retrieves the string starting from i and having a length j.");

console.write("enter your choice :");
int intchoice=int.parse(console.readline());
int intstart,intlength;
console.writeline("the original string :"+objstring.str);
if (1==intchoice) {
console.write("enter the position from where the substring should start :");
intstart=int.parse(console.readline());
console.writeline("the retrieved substring is :"+objstring.str.substring(intstart));
}
else {
console.write("enter the position from where the substring should start :");
intstart=int.parse(console.readline());
console.write("enter the length of the substring:");
intlength=int.parse(console.readline());
console.writeline("the retrieved substring is :"+objstring.str.substring(intstart,intlength));
}
}

private void mtdlower() {
console.writeline("string.tolower() - > returns the string with all its characters in lower case");
console.writeline("the original string : " + objstring.str);
console.writeline("the string in lower case : " +objstring.str.tolower());
}

private void mtdupper() {
console.writeline("string.toupper() - > returns the string with all its characters in upper case");
console.writeline("the original string : " + objstring.str);
console.writeline("the string in upper case : " +objstring.str.toupper());
}

private void mtdtrim() {
console.writeline("string.trim() - > removes white space characters from the begininning and end of the string and also specified characters.");

console.writeline("1. string.trim() -> removes white space characters from beginning and end of the string.");

console.writeline("2. string.trim(char[] c) -> removes all occurances of set of characters in the array from the beginning and end of string.");

console.write("enter your choice :");
int intchoice=int.parse(console.readline());
console.writeline("the original string : " +objstring.str);
if (1==intchoice) {
console.writeline("the trimmed string is : "+objstring.str.trim());
}
else {
console.write("enter the character array : ");
char[] c=console.readline().tochararray();
console.writeline("the string after removing characters from the array : " + objstring.str.trim(c));

}
}

private void mtdtrimend() {
console.writeline("string.trimend(char[] c) - > removes all occurances of the set of characters in the array from the end of the string.");

console.writeline("the original string is : " + objstring.str);
console.write("enter the character array : ");
char[] c=console.readline().tochararray();
console.writeline("the modified string is : "+objstring.str.trimend(c));
}

private void mtdtrimstart() {
console.writeline("string.trimstart(char[] c) - > removes all occurances of the set of characters in the array from the start of the string.");

console.writeline("the original string is : " + objstring.str);
console.write("enter the character array : ");
char[] c=console.readline().tochararray();
console.writeline("the modified string is : "+objstring.str.trimstart(c));
}
} (转贴)
文章整理:站长天空 网址:http://www.z6688.com/
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

文章页数:[1] 


放大字体显示 缩小字体显示 打印文章 推荐给朋友
热门文章
·使用C#编写Windows Forms应用程序(转)-.NET教程,Windows开发
·C#学习杂记-.NET教程,C#语言
·将文本格式的文章转换为html/xml格式文本的功能封装到Javabean-JSP教程,Java技巧及代码
·用java小程序applet实现无限级树结构-JSP教程,Java技巧及代码
·《.net编程先锋C#》第一章 C#简介-.NET教程,C#语言
·企业人事信息管理系统1.0-ASP教程,数据库相关
·《.net编程先锋C#》第三章 第一个C#应用程序-.NET教程,C#语言
·《.net编程先锋C#》第二章 理论基础-公用语言 运行环境-.NET教程,C#语言
·Windows应用程序调试必备的--符号文件(Symbols)-.NET教程,评论及其它
·c#反编译微软msdn2003的帮助文档,并将反编译结果保存到一个sqlserver数据库中
最新文章
·vista的新特性:懒人的安全感_windows vista
·photoshop为情侣照片打造韩式梦幻相框_photoshop教程
·专访seobbs站长乐思蜀_站长访谈
·嘟嘟网络陈艺光:诚信是一种信仰_站长访谈
·俺自己黄修源:只问耕耘,不问收获_站长访谈
·李向华:如何提高论坛用户粘性_站长访谈
·给windows vista系统网络和共享中心“换脸”_windows vista
·胡宪东谈搜索优化的实战_站长心得
·网站快速成功的九个步骤_站长心得
·google pr数字背后的含意_google推广
相关主题
  • stringwriter实现的一个功能_c#应用
  • StringHelper-JSP教程,Java技巧及代码
  • String类型两种不同实例化方式-JSP教程,Java技巧及代码
  • StringBuffer帮你减轻Java的负担-JSP教程,Java技巧及代码
  • String类使用的例子(1)-.NET教程,C#语言
  • 西部数码虚拟主机

    友情链接
    CNNIC 西部数码
    万网 自助建站
    虚拟主机 asp空间
    域名注册 域名
    域名申请 主页空间
    论坛空间 网站空间
    国际域名 虚拟空间
    空间租用 DDOS防火墙
    成都主机托管 四川主机托管
    主机租用 服务器租用
    网站目录 自助建站
    虚拟主机 网址大全
    软件下载
    自助链接
    虚拟主机资讯 特价虚拟主机
    版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!
    关于我们:站长天空:专业提供最新的站长资讯、在线教程、虚拟主机权威评测、虚拟主机性能对比、网站制作教程,开发教程,站长工具。包括网页制作教程、冲浪宝典、编程参考、操作系统、软件教学、行业动态等。
    特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。
    发表评论 打印  刷新     关闭