How to change a string to ProperCase 
Author Message
 How to change a string to ProperCase

I would like to have a function because I cannot find it in
vb.net that convert the first letter of a word to Upper

In vb6 I used to do
Public Function CapitaliseFirst(ByRef txtString As String) As String
        If Len(txtString) = 0 Then
            CapitaliseFirst = ""
        Else
            CapitaliseFirst = UCase(txtString.Substring(1)) &
txtString.substring(Len(txtString) - 1)  )
        End If
    End Function

OBVIOUSLY I want to use vb.net way of achiving the same
any idea

Also i would have a group box and I Tried the following but didnt work!!

  Public Sub Validate(ByVal CurrentGroupBox As GroupBox)
        '//convert all to propercase
        Dim objcontrol As Object
        Dim i As Int16
        '// = me, panel, or other container
        For i = 0 To CurrentGroupBox.Controls.Count - 1
            objcontrol = CurrentGroupBox.Controls.Item(i)
            If objcontrol.GetType.Name = "TextBox" Then
'//i would like to use a vbnet way of doing this conversions.A
StrConv(objcontrol.Text, VbStrConv.ProperCase)
            End If
        Next
    End Sub

Any ideas?
Thanks
Gabriel

*** Sent via Developersdex http://www.*-*-*.com/ ***
Don't just participate in USENET...get rewarded for it!



Mon, 27 Dec 2004 02:44:54 GMT  
 How to change a string to ProperCase
Dim sTxt As String =
System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase("how
are you?")

HTH
Corrado



Mon, 27 Dec 2004 02:56:00 GMT  
 How to change a string to ProperCase
Ciao Corrado
I suppose you are Italian.Sono Italiano anchio
I will answer in English so that everybody can benefit

Thanks for your reply.My only concern with your reply is

by calling all that system.blah blah will it not slow it down
would not be as slow as calling vb6 functionality.
what about the string builder I donot know much about it

any other suggestions

Thanks
Gabriel

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Mon, 27 Dec 2004 05:54:02 GMT  
 How to change a string to ProperCase
You can shorten the specific conversion call by importing
systems.globalization, but it eventually executes the same code.  I don't
see where what Corrado suggested would significantly impact the speed of
your app.  It should certainly be faster than the way you were having to do
it in VB6

--
VBnet4Apps
http://www.avenuezx.com/vbnet4apps/



Mon, 27 Dec 2004 06:27:51 GMT  
 How to change a string to ProperCase
Ciao, effettivamente sono Italiano... non ci voleva molto a capirlo... ;-)

I've used the long syntax in order to prevent the Imports statements that it
is somewhat confusing in some snippets, anyway don't know about performances
but i think that using CLR classes will be easier and safer that writing
your own functions just to duplicate CLR functionality.

HTH
Ciao
Corrado



Quote:
> Ciao Corrado
> I suppose you are Italian.Sono Italiano anchio
> I will answer in English so that everybody can benefit

> Thanks for your reply.My only concern with your reply is

> by calling all that system.blah blah will it not slow it down
> would not be as slow as calling vb6 functionality.
> what about the string builder I donot know much about it

> any other suggestions

> Thanks
> Gabriel

> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



Mon, 27 Dec 2004 06:38:16 GMT  
 How to change a string to ProperCase
Grazie Corrado

It works

However because I need to convert lots of textboxes that are contained
in groupbox

I have written this function that accepts the groupbox
loops through all the objects that are placed in the groupbox and when
it finds a text box it should convert to title case however for 01
reason or another it doesnt do that can you see why?

  Public Sub Validate(ByRef CurrentGroupBox As GroupBox)
        '//convert all to propercase
        Dim objcontrol As Object
        Dim i As Int16
        '// = me, panel, or other container
        For i = 0 To CurrentGroupBox.Controls.Count - 1
            objcontrol = CurrentGroupBox.Controls.Item(i)
            If objcontrol.GetType.Name = "TextBox" Then

System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(obj
control.Text)
            End If
        Next
    End Sub

Thanks
Gabriel

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Mon, 27 Dec 2004 15:46:05 GMT  
 How to change a string to ProperCase
Some problems around, first of all turn on option strict so that you can
avoid 'evil' casting

Here's a working version of your routine (Option Strict On)

 Public Sub Validate(ByRef CurrentGroupBox As GroupBox)
  '//convert all to propercase
  Dim objcontrol As Object
  Dim i As Int16
  '// = me, panel, or other container
  For i = 0 To CShort(CurrentGroupBox.Controls.Count - 1)
   objcontrol = CurrentGroupBox.Controls.Item(i)
   If TypeOf (objcontrol) Is TextBox Then
    Dim oTxtBox As TextBox = DirectCast(objcontrol, TextBox)
    oTxtBox.Text =
(System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(oTxtBo
x.Text))
   End If
  Next
 End Sub

HTH
Corrado



Quote:
> Grazie Corrado

> It works

> However because I need to convert lots of textboxes that are contained
> in groupbox

> I have written this function that accepts the groupbox
> loops through all the objects that are placed in the groupbox and when
> it finds a text box it should convert to title case however for 01
> reason or another it doesnt do that can you see why?

>   Public Sub Validate(ByRef CurrentGroupBox As GroupBox)
>         '//convert all to propercase
>         Dim objcontrol As Object
>         Dim i As Int16
>         '// = me, panel, or other container
>         For i = 0 To CurrentGroupBox.Controls.Count - 1
>             objcontrol = CurrentGroupBox.Controls.Item(i)
>             If objcontrol.GetType.Name = "TextBox" Then

> System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(obj
> control.Text)
>             End If
>         Next
>     End Sub

> Thanks
> Gabriel

> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



Mon, 27 Dec 2004 17:54:47 GMT  
 How to change a string to ProperCase

Ciao

Grazie

Your version of function is much better and works
I am just starting on .net .

Grazie

Gabriel

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Mon, 27 Dec 2004 20:12:32 GMT  
 How to change a string to ProperCase
One last thing

I have input in my textbox all in UPPERCASE expecting to convert to
titlecase but didnt!!

It only works if you start with a lower case.
What about if somebody by mistake types all in uppercase.

Is this the way it works?

Thanks
Gabriel

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Mon, 27 Dec 2004 20:25:59 GMT  
 How to change a string to ProperCase
Gabriel,
    Just use ToLower() on the string before the TitleCase call and it should
work.

Ron Allen

Quote:
> One last thing

> I have input in my textbox all in UPPERCASE expecting to convert to
> titlecase but didnt!!

> It only works if you start with a lower case.
> What about if somebody by mistake types all in uppercase.

> Is this the way it works?

> Thanks
> Gabriel

> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



Mon, 27 Dec 2004 21:30:50 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. changing UPPERCASE to ProperCase

2. Propercase

3. ProperCase Function/Routine

4. Prob#2, ProperCase issue

5. Changing string within a string

6. Search a string and change a character if it exists in the string

7. Change colors intext string

8. Changing String Datatype to Field type

9. loop changing strings in controls' names

10. changing formatting for defined text strings

11. changing the value of a string passed to a function

12. Changing the base of a string in VB.NET

 

 
Powered by phpBB® Forum Software