VB icon

_ String Functions _

Email
Submitted on: 2/4/2015 11:41:00 PM
By: KRYO_11 (from psc cd)  
Level: Intermediate
User Rating: By 7 Users
Compatibility: VB 5.0, VB 6.0
Views: 2408
 
     Includes many common useful string functions. Reverse string, Remove extra spaces, Delimit string, Alternating caps, Proper case, and Count number of occurances of a string in a string. Vote if you like it!
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: _ String Functions _
' Description:Includes many common useful string functions. Reverse string, Remove extra spaces, Delimit string, Alternating caps, Proper case, and Count number of occurances of a string in a string. Vote if you like it!
' By: KRYO_11 (from psc cd)
'**************************************

Public Function ReverseString(TheString As String) As String
ReverseString = ""
For i = 0 To Len(TheString) - 1
ReverseString = ReverseString & Mid(TheString, Len(TheString) - i, 1)
Next i
End Function
Public Function RemoveExtraSpaces(TheString As String) As String
Dim LastChar As String
Dim NextChar As String
LastChar = Left(TheString, 1)
RemoveExtraSpaces = LastChar
For i = 2 To Len(TheString)
NextChar = Mid(TheString, i, 1)
If NextChar = " " And LastChar = " " Then
Else
RemoveExtraSpaces = RemoveExtraSpaces & NextChar
End If
LastChar = NextChar
Next i
End Function
Public Function DelimitString(TheString As String, Delimiter As String) As String
DelimitString = ""
For i = 1 To Len(TheString)
If i <> Len(TheString) Then
DelimitString = DelimitString & Mid(TheString, i, 1) & Delimiter
Else
DelimitString = DelimitString & Mid(TheString, i, 1)
End If
Next i
End Function
Public Function AltCaps(TheString As String, Optional StartWithFirstCharacter As Boolean = True) As String
Dim LastCap As Boolean
AltCaps = ""
If StartWithFirstCharacter = False Then LastCap = True
For i = 1 To Len(TheString)
If LastCap = False Then
AltCaps = AltCaps & UCase(Mid(TheString, i, 1))
LastCap = True
Else
AltCaps = AltCaps & LCase(Mid(TheString, i, 1))
LastCap = False
End If
Next i
End Function
Public Function Propercase(TheString As String) As String
Propercase = UCase(Left(TheString, 1))
For i = 2 To Len(TheString)
If Mid(TheString, i - 1, 1) = " " Then
Propercase = Propercase & UCase(Mid(TheString, i, 1))
Else
Propercase = Propercase & LCase(Mid(TheString, i, 1))
End If
Next i
End Function
Public Function CountCharacters(TheString As String, CharactersToCheckFor As String) As Integer
 Dim Char As String
 Dim ReturnAgain As Boolean
 CountCharacters = 0
 For i = 1 To Len(TheString)
If i < (Len(TheString) + 1 - Len(CharactersToCheckFor)) Then
Char = Mid(TheString, i, Len(CharactersToCheckFor))
ReturnAgain = True
Else
Char = Mid(TheString, i)
ReturnAgain = False
End If
If Char = CharactersToCheckFor Then CountCharacters = CountCharacters + 1
If ReturnAgain = False Then GoTo NextPos
Next i
NextPos:
End Function


Other 19 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.