开发者

Linq to Entity convert string to proper case

Could you show me an example how to convert string when I am selecting using Linq to entity to pro开发者_JAVA技巧per case? Thank you


I dont think you need purely LINQ for this.

Have a look at this example

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

So in a LINQ select you could use something like

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜