Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Converting a String to Alternating caps.

Author: DevASP
Download Source Code : 647_AlternateCaps.zip

This article is about how you can convert a string to alternating caps. Enter the string you want to convert into alternating caps and click the button.

You will see the output on a label control with one letter in small and other in caps.

 

Steps you will do.

 

Start visual studio and create a new window application. Set the following properties of the form object.

 

Name = “frmmain”

Text = “Alternate Caps”

MaximizeBox = “False”

 

 

Drop a label control on the form and set its following properties.

 

Name = “Label1”

Text = “Enter a string to convert it into altenate caps”

 

 

Place a text field so that user can enter the string in that field and set its following properties.

 

Name = “tbstring”

Text = “”

 

 

Place a button control on the form and set the following properties.

 

Name = “btconvert”

Text = “Convert To AlterNate Caps”

 

 

Drop another label control on the form to show the output string. Set its following properties.

 

Name = “lbfinalstring”

Text = “”

Size = “208, 104”

 

 

Open the code window of form and write the following code in the click event of the button to convert the entered string into alternating caps.

 

lbfinalstring.Text = StringAlternate(tbstring.Text, False)

 

In the above code there is a call to the function “tringAlternate” which is as below. So create a function with the name “StringAlternate’ as given below.

 

Public Function StringAlternate(ByVal stext As String, ByVal StartLowerCase As Boolean) As String

 

Dim i As Int16 = 1

Dim bAlternate As Boolean

Dim sBuild As String

bAlternate = StartLowerCase

 

Do Until i = Len(stext) + 1

     If bAlternate = False Then

          StringAlternate = StringAlternate & UCase(Mid(stext, i, 1))

          bAlternate = True

      Else

          StringAlternate = StringAlternate & LCase(Mid(stext, i, 1))

           bAlternate = False

      End If

     

      i = i + 1

 

Loop

 

 

End Function

 

 

Run your application. Enter some text in the test box and click the convert button to convert the entered string into alternating caps.

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Getting system supported colors.

Disclaimer - Privacy
© 2002-2017 DevASP.net