views:

112

answers:

1

Could you show me an example how to convert string when I am selecting using Linq to entity to proper case? Thank you

+1  A: 

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);
astander
In my case I'm binding datalist with linq to entity, thats why I need to convert when Im selecting
George
I have some data like TABLE, WORD, APPLE and I need to convert them to Table, Word, Apple ...
George
Then this should help you with that.
astander