Trying to convert to titlecase problem

  • Thread starter Thread starter darrel
  • Start date Start date
D

darrel

I'm trying to take the value of a textbox and titleCase. A recent question
posted here by myself sent me to this page:

http://msdn2.microsoft.com/en-gb/library/system.globalization.textinfo.totitlecase.aspx

Where I found this sample code:

Dim instance As TextInfo
Dim str As String
Dim returnValue As String

returnValue = instance.ToTitleCase(str)

Upon trying to use it on my page:

Dim str_title As String
Dim instance As System.Globalization.TextInfo
Dim str_titlePreCaseChange As String = Trim(tbx_title.Text)
str_title = instance.ToTitleCase(str_titlePreCaseChange)

I get an error on the last line of :
Object reference not set to an instance of an object.

....and I'm not sure why.

-Darrel
 
Hi,
Incorrect One : Dim instance As System.Globalization.TextInfo
Correct One : Dim instance As System.Globalization.TextInfo = New
System.Globalization.TextInfo

Thanks and regards,
Manish Bafna.
MCP and MCTS.
 
Try this...

System.Globalization.CultureInfo c = new
System.Globalization.CultureInfo("hi-IN");
System.Globalization.TextInfo d = c.TextInfo;
string title = d.ToTitleCase("ginesh kumar");
 
Incorrect One : Dim instance As System.Globalization.TextInfo
Correct One : Dim instance As System.Globalization.TextInfo = New
System.Globalization.TextInfo

I'm using VB for this. The above example gives me a syntax error in VS: 'is
not accessible in this context because it is 'Private'

-Darrel
 
System.Globalization.CultureInfo c = new
System.Globalization.CultureInfo("hi-IN");
System.Globalization.TextInfo d = c.TextInfo;
string title = d.ToTitleCase("ginesh kumar");

Thanks, Manish.

What, exactly, is the CultureInfo part for?

-Darrel
 
Well, after some more googling, I found this:

str_title =
System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(Trim(tbx_title.Text).ToLower(System.Globalization.CultureInfo.InvariantCulture))



And that seems to work. Wordy, but it works. ;o)



_Darrel
 
Back
Top