Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Format a CamelCase string to a CamelCase sentence
Author:
Sachin Telang
Submitted:
10/17/2008
Version:
VB6
Compatibility:
VB6
Category:
String Manipulation
Views:
13219
Format a CamelCase string to a CamelCase sentence. The program makes use of non-recursive logic. The code can be handy to extract words from a CamelCased string. It will also detects ALL CAPS pattern in the string and extracts it as a single word for example "MyVISACard12" will be converted to "My VISA Card 1 2"'
Declarations:
'none
Code:
Function camelCaseWords(myString As String) As String Dim pos, curCharCaps, allCapsPattern, bprevCharCaps Dim strWithWords myString = "MyVISACardHasBeenExpired" strWithWords = "" bprevCharCaps = False For i = 1 To Len(myString) aChar = Mid(myString, i, 1) If (Not IsNumeric(aChar)) And (aChar <> Space(1)) Then If (Asc(aChar) >= 65 And Asc(aChar) <= 90) Then curCharCaps = True ' scan for the ALL CAPS pattern Like "IOPoint" this should be "IO Point" If bprevCharCaps = False Then aChar = Space(1) + aChar Else If aChar <> Space(1) Then allCapsPattern = True End If End If Else curCharCaps = False If (bprevCharCaps = True And allCapsPattern = True) Then aChar = Mid(myString, i - 1, 2) aChar = Space(1) + aChar strWithWords = Left(strWithWords, Len(strWithWords) - 1) allCapsPattern = False End If End If strWithWords = strWithWords + aChar bprevCharCaps = curCharCaps Else ' treat any numbers as separate word aChar = Space(1) + aChar strWithWords = strWithWords + aChar bprevCharCaps = False End If Next camelCaseWords = strWithWords End Function
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement