频道直达 - 学院 - 下载 - 交易 - 特效 - 字库 - 手册 -排名-工具- 繁體
网页教学网站开发 设为首页
加入收藏
联系我们
建站搜索: 常用广告代码   用户注册 | 用户登陆
您当前的位置:中国建站之家 -> 网站开发设计技术教程 -> Asp.Net教程 -> String类使用的例子(3)

String类使用的例子(3)

作者:未知  来源:转载  发布时间:2005-7-20 9:57:58  发布人:acx

减小字体 增大字体

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));
}
}
       

将本文收藏到QQ书签与更多好友分享
[打 印]
[] [返回上一页] [收 藏]
下一篇文章:String类使用的例子(2)
∷相关文章评论∷    (评论内容只代表网友观点,与本站立场无关!) [更多评论...]
精彩推荐
热门文章
· 注册码大全二
· 注册码大全四
· 注册码大全一
· 要10G免费网络硬盘的请进..
· 通过google 赶快来赚美金..
· 注册码大全十
· 头像-qq头像(qq新头像)4..
· 让你轻松架设FTP服务器1..
· 注册码大全三
· 梦幻背景图片7
· 卡通动物图片6
· 网页制作素材-按钮素材2..
· 让你轻松架设FTP服务器5..
· 风景图片8
· 注册码大全九
· 让你轻松架设FTP服务器2..
关注此文读者还看过
· Flash 8 少为人知的特性..
· 一个个人网页自动化生成..
· XML技术上传文件3
· 使用MS SQL7的LINKED SE..
· 亚马逊市值达Google两倍..
· FW MX和Flash MX的亲密合..
· 详细介绍优化mysql性能的..
· Google及雅虎搜索引擎优..
· PHP聊天室技术
· Google成功收购YouTube ..
· 教你如何去掉网页上的Fl..
· 男子自称博士网上“出租..
· 破解文字的禁制:Aqua抓图..
· MySQL数据库基础教程
· 一段取得翻唱排行榜上歌..
· 自定义控件--xp风格按钮..
相关文章
· 提高ASP的速度的方法:GetS..
· 深入理解Ruby语言中的Strin..
· ADO初学者教程:ADO 通过Ge..
· 符合XHTML Strict 1.0标准的..
· 分析(X)HTML Strict 下的嵌..
· 在Javascript中为String对象..
· JScript 方法 - concat 方法..
· 函数版的 String.trim() 方..
· 谈谈Flash的一些语法基础和..
· 实现word的批量替换功能,a..
· 构造ConnectionString的方法..
· 加密QueryString数据
· String添加trim,ltrim,rtri..
· 用GetString来提高ASP的速度..
· Distributed Transactions
· 怎样才能将query string从一..
关于本站 - 网站帮助 - 广告合作 - 下载声明 - 友情连接 - 网站地图 - 人才招聘
网站合作、内容监督、商务咨询:QQ: 9576619
Copyright ? 2005--2008 中国建站之家版权所有
粤ICP备05092265号