Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Visual Basic
Expertise: Beginner
Oct 26, 1999



Application Security Testing: An Integral Part of DevOps

Count Substrings

This little routine demonstrates how easily you can determine the number of substrings within a string, given any specified separator character(s). Pass the string to be parsed, and the separator, which might be multiple characters long, and DCount returns the number of substrings:
Public Function DCount(ByVal vData As String, _
	SP As String) As Integer
	Dim x As Integer
	Dim n As Integer
	If vData = "" Or SP = "" Then Exit Function
	vData = Trim(vData)
	n = 1
	DCount = 1
		x = InStr(n, vData, SP, vbTextCompare)
		If x > 1 And x < (Len(vData) - Len(SP)) _
			DCount = DCount + 1
		End If
		n = x + Len(SP)
	Loop Until x = 0
End Function

s = "GTL-00030/22*M121222*C001"
cnt = DCount(s ,"*")	->	cnt=3
cnt = DCount(s ,"/")	->	cnt=2
cnt = DCount(s ,"0")	->	cnt=7
Tan Shing
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date