Linq to Entity将字符串转换为正确的大小写

时间:2010-04-25 16:11:18

标签: linq-to-entities

当我选择使用Linq到实体到正确的情况时,你能告诉我一个如何转换字符串的例子吗?谢谢

1 个答案:

答案 0 :(得分:2)

我认为你不需要纯粹的LINQ。

看一下这个例子

string sampleString = "this is a title";
CultureInfo currentCulture = System.Threading.Thread.CurrentThread.CurrentCulture;
TextInfo currentInfo = currentCulture.TextInfo;
sampleString = currentInfo.ToTitleCase(sampleString); 

//output:
//This Is A Title

TextInfo.ToTitleCase Method

所以在LINQ选择中你可以使用像

这样的东西
CultureInfo currentCulture = System.Threading.Thread.CurrentThread.CurrentCulture;
TextInfo currentInfo = currentCulture.TextInfo;
List<string> testList = new List<string> { "foo", "bAr", "fOO bar Test tAdA" };
var correct = from s in testList
              select currentInfo.ToTitleCase(s);