Converting a sentence into CamelCase format in Microsoft VB.NET & ASP.NET
Microsoft VB.NET, ASP.NET and C#.NET lacks the function to allow programmers to convert a string, or even a whole sentence into Camel Case format. Therefore, i have written a microsoft .net functions to do just that. This comes very handy especially in converting a list of names into Camel Case format, or converting a string of addresses and many other applications. You name it. If you do not know what a Camel Case format look like, see the example below:
For instance, we are going to convert the following files into Camel Case format.
Dim Sentence1 As String = "is john smith working in microsoft?"
Dim Sentence2 As String = "michael t. ashby is a GREAT programmer. he is young."
Dim Output1, Output2 As String
Output1 = CCase(Sentence1)
Output2 = CCase(Sentence2)
The converted output will be
Output1 : "Is John Smith Working In Microsoft?"
Output2 : "Michael T. Ashby Is A Great Programmer. He Is Young."
Simply copy and paste the following codes below into your microsoft vb.net, asp.net programming code and you can use it right away.
Public Function CCase(ByVal iString As String) As String
'This function converts a string into "Camel Case" format
Dim oString As String = "" 'initialise output string
Dim iLength As Integer = Len(iString) 'the length of input string
Dim P As Integer = 1 'set pointer to start at character 1
Dim iChar As String 'individual stripped character
Dim UpperFlag As Boolean 'flag to mark upper case is required or not
iString = LCase(iString) 'convert to lower case string
While P <= iLength ' while not end of the string (pointer)
iChar = Mid(iString, P, 1) 'strip each character out of the string one by one
If P = 1 Then 'first character
UpperFlag = True 'change first character to upper case
End If
If iChar = " " Or iChar = "-" Then 'blank field encountered.
UpperFlag = True 'raise the flag to mark the next character as upper case
Else 'non-blank field encountered
If UpperFlag = True Then 'if the flag is raised
iChar = UCase$(iChar) 'change the character to uppercase
UpperFlag = False 'undo raising the flag
End If
End If
oString &= iChar 'reassemble characters back into a string as output
P += 1 'next pointer
End While
Return (oString) 'return the reassembled output string
End Function
VB.NET : Convert A Sentence Into Camel Case Format
Posted by Fluffy | 4:05 AM | ccase, vb.net camel case | 1 comments »
Subscribe to:
Post Comments (Atom)

I haven’t any word to appreciate this post.....Really i am impressed from this post....the person who create this post it was a great human..thanks for shared this with us. http://psiprograms.com