2014.12.11 知识点总结

SPOJ problem 4 所学知识

1 将键盘上输入的字符串重新显示出来,代码如下:

            string input;

            input = Console.ReadLine();

            Console.WriteLine(input);

            Console.ReadKey();

把字符串转变为字符数组

方法 1:

            string input;

            char[] toCharArray;

            input = Console.ReadLine();

方法 2:

            string input;

            char[] charArray;

            input = Console.ReadLine();

            for (int i = 0; i < input.Length; i++)

            {

                charArray = new char[input.Length];

                charArray[i] = input[i];

                Console.WriteLine(charArray[i]);

                Console.ReadKey();

            }

给字符型变量付字符 ,注意要点是“单引号”

char c1 = 'X'; //注意是单引号 char c2 = 'x0058'; //用十六进制表示 char c3 = (char)88; //用数字转换 char c4 = 'u0058'; //用 Unicode 表示 

删除字符串中的指定字符

方法1

            char[] deleteChar = { 'a', 'b', 'd' };

            string input = Console.ReadLine();

            string output = input.Trim(deleteChar);

            Console.WriteLine(output);

            Console.ReadKey();

删除数组中的指定元素

string   []   arr   =   {   "abc1 ",   "abc2 ",   "abc3 ",   };          ArrayList   al     =   new   ArrayList(arr);          al.RemoveAt(1); 

如何复制栈

            Stack<string> colour = new Stack<string>();

            colour.Push("yellow");

            colour.Push("white");

            colour.Push("green");

            colour.Push("red");

            Console.ForegroundColor = ConsoleColor.White;

            foreach (string number in colour)

            {

                Console.WriteLine(number);

            }

            Stack<string> stack = new Stack<string>(colour.ToArray());

            Console.ForegroundColor = ConsoleColor.Green;

            foreach (string number in stack)

            {

                Console.WriteLine(number);

            }

            Console.ReadKey();

判断判断字符串是否有字符和数字

stristring str = Console.ReadLine(); if (char.isLetter(str)) { } else if (char.IsDigit(str)) { }ng str = Console.ReadLine();

stristring str = Console.ReadLine(); if (char.IsDigit(str)) { } else if (char.IsDigit(str)) { }ng str = Console.ReadLine();

 

 

 

 

 

原文地址:https://www.cnblogs.com/xumaodun/p/4158518.html