Is there a function that will Capitalize words in a string?

  • Thread starter Thread starter Robert Johnson
  • Start date Start date
R

Robert Johnson

Hi all. Checked the docs and all I can find is UCase but that will convert
everything to upper. What I want is when my users enter say a name into a
text box I want to just upper the first char for them if they forget to.

TIA

Robert
 
Robert,

VB's StrConv function will do that. For example:

StudentName = StrConv(StudentName , VbStrConv.ProperCase)

I don't know of a ".Net" way of accomplishing the same thing.

Kerry Moorman
 
Robert Johnson said:
Hi all. Checked the docs and all I can find is UCase but that will convert
everything to upper. What I want is when my users enter say a name into a
text box I want to just upper the first char for them if they forget to.

Dim x As String = Textbox1.Text.Substring(1).ToUpper

You can play it anyway you want with a function of your own making or
whatever to return the string with the first character in upper case.

Function 1stCharUpper(ctrl as Textbox)

do what you have to do in the manipulation of the string.

dim x as string = ctrl.Text.Substring(1).ToUpper

return x = x & ctrl.text.substring(2, length)

end function
 
Kerry said:
Robert,

VB's StrConv function will do that. For example:

StudentName = StrConv(StudentName , VbStrConv.ProperCase)

I don't know of a ".Net" way of accomplishing the same thing.

For ProperCase, the ".NET" way is exactly the same as VB6, no difference.

The following is from VB2005 Help -

Visual Basic 6.0 Visual Basic 2005 Equivalent
vbUpperCase VbStrConv.UpperCase

vbLowerCase VbStrConv.LowerCase

vbProperCase VbStrConv.ProperCase

vbWide VbStrConv.Wide

vbNarrow VbStrConv.Narrow

vbKatakana VbStrConv.Katakana

vbHiragana VbStrConv.Hiragana

vbUnicode No equivalent constant. You can achieve the same functionality
by using the Convert method.

vbFromUnicode No equivalent



ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
It is hard to find, but it's there in the framework:
System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(YourString)
--
David Anton
www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Python
Instant C#
Instant VB
Instant C++
Instant Python
C++ to C# Converter
C++ to VB Converter
 
Thank you Kerry

Robert
Kerry Moorman said:
Robert,

VB's StrConv function will do that. For example:

StudentName = StrConv(StudentName , VbStrConv.ProperCase)

I don't know of a ".Net" way of accomplishing the same thing.

Kerry Moorman
 
Thank you ShaneO

Robert
ShaneO said:
For ProperCase, the ".NET" way is exactly the same as VB6, no difference.

The following is from VB2005 Help -

Visual Basic 6.0 Visual Basic 2005 Equivalent
vbUpperCase VbStrConv.UpperCase

vbLowerCase VbStrConv.LowerCase

vbProperCase VbStrConv.ProperCase

vbWide VbStrConv.Wide

vbNarrow VbStrConv.Narrow

vbKatakana VbStrConv.Katakana

vbHiragana VbStrConv.Hiragana

vbUnicode No equivalent constant. You can achieve the same functionality
by using the Convert method.

vbFromUnicode No equivalent



ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
Thank you M. Arnold

Robert
Mr. Arnold said:
Dim x As String = Textbox1.Text.Substring(1).ToUpper

You can play it anyway you want with a function of your own making or
whatever to return the string with the first character in upper case.

Function 1stCharUpper(ctrl as Textbox)

do what you have to do in the manipulation of the string.

dim x as string = ctrl.Text.Substring(1).ToUpper

return x = x & ctrl.text.substring(2, length)

end function
 
Thank you David

Robert
David Anton said:
It is hard to find, but it's there in the framework:
System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(YourString)
--
David Anton
www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Python
Instant C#
Instant VB
Instant C++
Instant Python
C++ to C# Converter
C++ to VB Converter
 
Kerry,

Probably you mean with the .Net way. A way in the .Net namespace System.Net,
there is not, this is in the .Net namespace VisualBasic.

Cor
 
Back
Top