0
저는 Linq를 처음 들었고 누군가가 저를 도울 수 있는지 궁금합니다. 내 코드를 입력하려고하는 곳으로 첫 문자 나 단어를 대문자로 바꿀 것입니다. 선생님은 Linq를 사용하고 끝에 결과를 표시 해달라고 요청했습니다.Linq 목록에 문제가 생겼습니다.
예를 들어 "이름이 무엇입니까?"라고 말하면 "마크"또는 "마크 교수실"이라고 입력하면 "마크"와 "마크 갈리아"로 변경됩니다. 코드에 삽입 된 표시없이 입력 할 수 있기를 원합니다.
static void Main(string[] args)
{
string firstname;
string lastname;
string street;
string city;
string state;
string zip;
Console.Write("What is your first name: ");
firstname= Console.ReadLine();
Console.Write("What is your last name:");
lastname= Console.ReadLine();
Console.Write("What is your street name:");
street= Console.ReadLine();
Console.Write("What is your city name:");
city= Console.ReadLine();
Console.Write("What is your state name:");
state= Console.ReadLine();
Console.Write("What is your zip code:");
zip= Console.ReadLine();
}
public static string UppercaseWords(string value)
{
char[] array = value.ToCharArray();
List<string> items = new List<string>();
items.Add("firstName");
items.Add("lastName");
items.Add("street");
items.Add("city");
items.Add("state");
items.Add("zip");
var x =
from item in items
let UppercaseWords = item.ToCharArray()
select UppercaseWords;
foreach (var item in x)
Console.Write("{0} ", item);
if (array.Length >= 1)
{
if (char.IsLower(array[0]))
{
array[0] = char.ToUpper(array[0]);
}
}
for (int i = 1; i < array.Length; i++)
{
if (array[i - 1] == ' ')
{
if (char.IsLower(array[i]))
{
array[i] = char.ToUpper(array[i]);
}
}
}
return new string(array);
}
변경 사항을 보려면 어떻게 입력해야합니까?
당신이 LINQ 필요하지 않습니다. 이것은 당신이 필요로하는 것입니다 http://stackoverflow.com/questions/1206019/converting-string-to-title-case –