Code/Tea/Etc...

Duncan Mackenzie has too much time on his hands

The email I get...

Every day I get from 1 to 10 emails asking me various VB questions... some I answer by pointing to a link, some by providing code, and sometimes I just point people to the newsgroups or forums that exist for this type of question... but this time I thought I'd just post the question and answer into my blog ...


The Question (edited slightly):
I just want to ask how to make the string in to proper format..
ex...
input.
gerald

this must be the output:
Gerald

and i want it to interactively change when i'm inputing a string in a textbox..

And the answer is to put this code into the TextChanged event of your textbox;

Dim ci As Globalization.CultureInfo = _
    System.Threading.Thread.CurrentThread.CurrentCulture

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim pos As Integer = TextBox1.SelectionStart
TextBox1.Text = ci.TextInfo.ToTitleCase(TextBox1.Text)
If pos > 0 AndAlso pos <= TextBox1.Text.Length Then
TextBox1.SelectionStart = pos
End If
End Sub

The key is that the CultureInfo class provides a TextInfo instance, which in turn has a method of "ToTitleCase" on it... This KB article provides more info and also shows an alternate method to achieve the same results (StrConv()).

Published Monday, August 23, 2004 1:53 AM by Duncanma
Filed under:

Comments

 

hemal desai said:

Hi,

This message is not relevent to your post but i have a question and need your help.

I have come accross a situation where i need to develop an application to Send and Recived emails from POP3 Server and store it in the DB.

I found many wrapper classed on the net but i am not intrested in using them, as it has a question of beeing charged in future, what i want is to create my own class for the same. Can you suggest me the best approch & pass on a sample code snippet if you have any.

Regards
Hemal Desai

hemal.desai@gmail.com
August 23, 2004 2:20 AM
 

Duncan Mackenzie said:

August 23, 2004 2:35 AM
 

aredie said:

halo duncan mackenzie, i would like to ask abotu rsa and i have a dificulty how to make a program by vb 6.0 can you hel me my email in nung113@student.undip.ac.id pleaese my deadline is december 2004 and i wna;t to make my mom up sad if i pass the exam next year 2005
my brother can't school again if i late to make the proagram of rsa thank oyu
August 23, 2004 5:27 AM
Anonymous comments are disabled

This Blog

Syndication

News

This blog has moved to my own VB site

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker