码迷,mamicode.com
首页 > 其他好文 > 详细

字符串及字符的基础应用

时间:2014-07-31 09:46:56      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:os   io   for   ar   line   new   应用   har   

字符串的应用  #region 查找字符         //string str = "123456";         //foreach (char time in str)         //{         //    Console.WriteLine("{0}", time);         //}         //Console.ReadKey();         #endregion         #region  判断字母         //Console.WriteLine("输入字符");         //char c = (char)Console.Read();         //if (Char.IsLetter(c))         //{         //    if (char.IsLower(c))         //        Console.WriteLine("小写字母?");         //    else         //        Console.WriteLine("小写字母");         //}         //else         //    Console.WriteLine("非字母");         //Console.ReadKey();         #endregion 字符串的位置     string orgstr1 = "123456789";             string orgstr2 = "3456";             int orgstr3 = orgstr1.IndexOf(orgstr2, 0);             Console.WriteLine("位置是:" + orgstr3.ToString());             Console.ReadKey(); 结果:2 截取 string orgstr = "123456789";             string name = orgstr.Substring(2, 4);             Console.Write(name);             Console.ReadKey(); 结果:3456 string orgstr = "123456789";             string name = orgstr.Substring(3);             Console.Write(name);             Console.ReadKey(); 结果:456789

字符串的插入  string orgstr1 = "123456";             string orgstr2 = "789";             string orgstr3 = orgstr1.Insert(6, orgstr2);             Console.WriteLine(orgstr3);             Console.ReadKey(); 结果:123456789

字符串的删除  string orgstr1 = "123456789";             string orgstr2 = orgstr1.Remove(3,5);             Console.WriteLine(orgstr2);             Console.ReadKey(); 结果:1239 如无索引 默认为最后一位 字符串的替换  string orgstr1 = "123456";             string orgstr2 = orgstr1.Replace("3", "9");             Console.WriteLine(orgstr2);             Console.ReadKey(); 结果:129456

字符的分段  string orastr1 = "a|bb|ccc";             char[] arrag = new char[] { ‘|‘ };             string[] orastr2 = orastr1.Split(arrag, 3);             for (int i = 0; i < orastr2.Length; i++)             {                 Console.WriteLine(orastr2[i]);             }             Console.ReadKey(); 结果:a       bb       ccc

输出字符  string str = "123456";             foreach (char time in str)             {                 Console.WriteLine("{0}", time);             }             Console.ReadKey();

字符串及字符的基础应用,布布扣,bubuko.com

字符串及字符的基础应用

标签:os   io   for   ar   line   new   应用   har   

原文地址:http://www.cnblogs.com/huweijun/p/3879914.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!