article

This Basic VBScript demonstrates the Split Function (How To)

Email
Submitted on: 3/2/2019 4:57:00 PM
By: A_X_O 
Level: Beginner
User Rating: Unrated
Compatibility: VbScript (browser/client side)
Views: 1984
 
     Basic Demonstration of a useful VBScript function named Split. It's a very basic and simple example


 
				'
'------------------------------------------------------------------------------	'
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++	'
'		Demonstration: Windows 10, VBScript; Split String Function	'
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++	'
'										'
'	Purpose		:	Demonstrates VBScript Split Function		'
'	-----------------------------------------------------------------------	'
'	Creation Date	: 	01/03/2019 [dd/mm/yyyy]				'
'	Version		:	1.0						'
'	Designer	:	Fabian						'
'										'
'##############################################################################	'
'			MODIFICATION HISTORY					'
'------------------------------------------------------------------------------	'
'	Version		:	1:0	01/03/2019	Create the Sample	'
'										'
'------------------------------------------------------------------------------	'		
'
'			 
Dim StrDemo									'Dimensions: Memory Space for holding Variables
Dim ArrDemo		
Dim intCounter		
Dim IntMaxLoop		
Dim StrSplitText
Dim IntRandomSelect	
'
Public Const StrMBboxEx = "Split Part: "					'Constants: Static Strings
Public Const StrMBboxTxt = "Random Number: "
										'StrHelloFromPSC: The String to be split
'
Public Const StrHelloFromPSC = "Hello|from|Planet Source Code|This|is|a|VBScript|SPLIT|Demonstration"
'
'
										'The StrHelloFromPSC Can be any String regularly interupted by the same character.
										'For instance: C:\users\username\directories\videos\comedy\laurelhardy\blockheads.mp4
										'Or Even https://www.someplace.net/somedirectory/downloads/videos/comedy/filestore
										'Finaly you can use an unknown length string from: Wscript.ScriptFullName 					
'
	IntMaxLoop = 7								'The Maximum limit of the "Do While" Loop
	intCounter = 0								'The Current position of the "Do While" Loop
'
'
'
	StrDemo = Split(StrHelloFromPSC, "|", -1, 1)				'The Split Array: Stored in StrDemo(0) to StrDemo(8)
										'Example: StrDemo(0) = "Hello", StrDemo(2) = "Planet Source Code"
										'It is vital that the character your using to Split the string matches
										'In this demo the character is "|" the same as in "StrDemo" and "StrHelloFromPSC"
'
'
'
'---Example 01---UnComment the MsgBox------------------------------------------
'
Randomize 									'Randomly select a part of the Split String
'
	IntRandomSelect = Int((8 * Rnd) + 1)
										'Display the Random element of the split string and the Random number
'
	'Msgbox	StrMBboxEx & VbTab & StrDemo(IntRandomSelect) & VbCrLf & StrMBboxTxt & VbTab & IntRandomSelect
'------------------------------------------------------------------------------
'
'---Example 02---UnComment the MsgBox------------------------------------------
'
	'MsgBox StrDemo(3)							'Simply display element number 3
'
'------------------------------------------------------------------------------
'
'---Example 03---UnComment the MsgBox------------------------------------------
'
Do While intCounter < IntMaxLoop
	'MsgBox StrDemo(intCounter)						'Loop through the Array until element number 7
'
	intCounter = intCounter + 1						'Increment the counter so we know where we are
'
Loop
'
'------------------------------------------------------------------------------
'
'---Example 04---UnComment the MsgBox------------------------------------------
'
For IntSplit = 0 To intCounter -1
'
	StrSplitText = StrSplitText & Space(1) & StrDemo(IntSplit)		'StrSplitText: Holds the Parts of the String
'
	MsgBox StrSplitText 							'Build the complete String, One element at a time
'
Next
'
'------------------------------------------------------------------------------
'
'---Example 05---UnComment the MsgBox------------------------------------------
'
	'MsgBox StrSplitText 							'Display the entire Array all at once
'
'------------------------------------------------------------------------------


Other 17 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 article (in the Beginner category)?
(The article 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 article, please click here instead.)
 

To post feedback, first please login.