tags:

views:

30

answers:

2

Hi I am trying to convert some strings fetched from database into 'Title case' however it is not working for records like 'JAMES Smith'. The output is all the same. Any clue fellows ?

TextInfo companyName = new CultureInfo("en-US", false).TextInfo;

        if(!myRecord.IsDBNull(myRecord.GetOrdinal("GENCLIENTNAME")))
        {
            myCompany.GenClientName =companyName.ToTitleCase(myRecord.GetString(myRecord.GetOrdinal("GENCLIENTNAME")));
        }
+1  A: 

This is not supported; see the documentation:

However, this method does not currently provide proper casing to convert a word that is entirely uppercase, such as an acronym

I suggest you create your own method to convert the text in the way that you wish.

Daniel Renshaw
Err, missed that. Thanks.
Popo
That sounds like a workaround could be to first convert the text to lowercase!
Hans Kesting
I just did that and it worked like a charm. Thanks Hans !
Popo
+2  A: 

ToTitleCase doesn't convert all uppercase words. To fix this convert to lower case first.

companyName.ToTitleCase(myRecord.GetString(myRecord.GetOrdinal("GENCLIENTNAME")).ToLower())
Andrew Cooper
Thanks Andrew, works like a charm.
Popo
@Popo - you should accept his answer :)
Marko
@Marko it got me hold on a timer for 3 minutes =)
Popo
@Popo - I appologize :)
Marko
hehe nope, nevermind.
Popo