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

string

时间:2016-07-07 09:40:33      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:

技术分享
        static void Main(string[] args)
        {
            string str = "Now is time and";
            string word;
            ArrayList words = new ArrayList();
            int pos = str.IndexOf(" ");
            while (pos>0)
            {
                word = str.Substring(0,pos);
                words.Add(word);
                str = str.Substring(pos+1,str.Length-(pos+1));
                pos = str.IndexOf(" ");
                if (pos==-1)
                {
                    word = str.Substring(0,str.Length);
                    words.Add(word);
                }
            }
            foreach (var item in words)
            {
                Console.Write("  "+item);
            }
            Console.ReadKey();
        }
View Code

data="mike,stove";

sdata=data.Split(new char[]{‘,‘},data.length); 

String.Join(",",sdata);

技术分享
        static void Main(string[] args)
        {
            string s1 = "footbar";
            string s2 = "footbar";
            if (s1.Equals(s2))
            {
                Console.WriteLine("good");
            }
            else 
            {
                Console.WriteLine("bad");
            }

            string s3 = "footbaa";
            string s4 = "footbas";
            Console.WriteLine(s1.CompareTo(s2));
            Console.WriteLine(s1.CompareTo(s3));
            Console.WriteLine(s1.CompareTo(s4));

            Console.WriteLine(string.Compare(s1,s2));
            Console.WriteLine(string.Compare(s1,s3));
            Console.WriteLine(string.Compare(s1,s4));

            string se = "goodmorning";
            Console.WriteLine(se.EndsWith("ing"));
            Console.WriteLine(se.StartsWith("good"));

            string a1 = "hello, .welcome to my class";
            string a2 = "mike";
            int pos = a1.IndexOf(",");
            a1= a1.Insert(pos+2,a2);
            Console.WriteLine(a1);
            a1 = a1.Remove(pos+2,a2.Length);
            Console.WriteLine(a1);

            Console.WriteLine("goodsssgoodsssgood".Replace("goo","a"));
            Console.WriteLine("hello".PadLeft(10));
            Console.WriteLine("hello".PadRight(10));

            Console.WriteLine(string.Concat("hello"," , ","world"));
            Console.WriteLine("hellO".ToUpper());
            Console.WriteLine("HELLO".ToLower());

            string[] names = new string[] {" mi ke "," dav id "," r a y "};
            char[] chararray = new char[] {  };
            for (int i = 0; i <=names.GetUpperBound(0); i++)
            {
                names[i] = names[i].Trim(chararray[0]);
                //names[i] = names[i].TrimEnd(chararray[0]);
            }
            for (int i = 0; i <names.Length; i++)
            {
                Console.Write(names[i]);
            }

            string[] htmlComments = new string[]
            {
                "<!--startpage -->",
                "<!--startpage -->",
                "<!--startpage -->",
                "<!--startpage -->"
            };
            char[] commentChars = new char[] {<,!,-,>};
            for (int i = 0; i < htmlComments.Length; i++)
            {
                htmlComments[i] = htmlComments[i].Trim(commentChars);
               // htmlComments[i] = htmlComments[i].TrimEnd(commentChars);
            }
            for (int i = 0; i < htmlComments.GetUpperBound(0); i++)
            {
                Console.WriteLine(" "+htmlComments[i]);
            }
            Console.ReadLine();
        }
View Code
技术分享
            StringBuilder stBuff = new StringBuilder();
            stBuff.Insert(0,"hello",3);
            stBuff.Append("world");
            stBuff.Insert(5,",");

            char[] chars = new char[] {t,h,e,r,e };
            stBuff.Insert(5,""+new string(chars));
            Console.WriteLine(stBuff);
            Console.WriteLine(stBuff.Remove(9,5));
            Console.ReadLine();
View Code

 

string

标签:

原文地址:http://www.cnblogs.com/futengsheng/p/5648751.html

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