using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ch05t07
{
    class Program
    {
        static void Main(string[] args)
        {
            String str = "i am a girl";
            String[] word = str.Split(' ');
            foreach (string w in word)
            {
                Console.Write("\"{0}\" ",w);   
            }
            Console.ReadKey();
        }
    }
}

str.Split()以空格为单位,将string按单词划分开了。

Console.Write("\"{0}\" ",w);   完成给每个单词加上引号的功能。而\"对引号进行转义。功能虽小,但是很实用。
static void Main(string[] args)
        {
            String sorb;
            int i;
            Console.WriteLine("please input a string");
            sorb=Console.ReadLine();
            for (i = sorb.Length; i > 0; i--)
            {
                Console.Write(sorb[i-1]);
            }
            Console.ReadKey();
        }

完成反向输出字符的功能。将string看成字符数组,由后往前输出。

 
posted on 2015-04-12 15:21  若非菲lrr  阅读(182)  评论(0编辑  收藏  举报