英文句子中首字母转换为大写

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    
class Program
    {
        
static void Main(string[] args)
        {
            
string str = "Hello    my dear friend.";
            str.Trim();
            
char c = '\0';
            
string newStr = string.Empty;
            
for (int k = 0; k < str.Length; k++)
            {
                
//ASCII表中大小写字母正好相隔32,在ASCII表中32表示' ' A=65 Z=90 a=97 z=122   
                c = str[k];
                
if ((c >= 'a' && c <= 'z'|| c == ' ')
                {
                    
if (k == 0)
                        c 
-= ' ';

                    
if (c == ' ')
                    {
                        newStr 
+= c.ToString();
                        
if (str[k + 1!= ' ')
                        {
                            c 
= str[k + 1];
                            c 
-= ' ';
                            k
++;
                        }
                    }
                }
                newStr 
+= c.ToString();
            }
            Console.WriteLine(newStr);
            Console.ReadLine();
        }
    }
}
posted @ 2011-03-27 15:02  MrNobody_123456  阅读(334)  评论(0编辑  收藏  举报