Micro Focus QTP (UFT) Forums
Split a string with multiple delimiters in VBScript - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Split a string with multiple delimiters in VBScript (/Thread-Split-a-string-with-multiple-delimiters-in-VBScript)



Split a string with multiple delimiters in VBScript - nandha - 02-08-2018

How can i split the below string

Input: My?name/isNandha-welcome^
expected output:
My 
Name
isNandha
welcome

Thanks


RE: Split string from Special characters - Ankur - 02-09-2018

This is a good question.

I am sure there can be multiple way to solve this. Here is one of the solutions I created for you.  You just need to call ALL the delimiters you use in the string and the custom SplitExtended function will do the rest.

Essentially I am using the built in Replace function to run n times where n is the number of delimiters you supply in the array.

Code:
Function SplitExtended (sPhraseFn, aDelimiters)
'Find total number of delimiters. Remember ubound starts from 0 index    
iNoOfDelimiters = UBound(aDelimiters)

'Replace all your delimiters with space      
For Iterator = 0 To iNoOfDelimiters
sPhraseFn = Replace (sPhraseFn, aDelimiters(Iterator)," ")    
Next    

SplitExtended = sPhraseFn
End Function

sPhrase = "My?name/isNandha-welcome^"
sPhraseClean = SplitExtended(sPhrase, Array("?","/","-","^"))
msgbox sPhraseClean



RE: Split string from Special characters - nandha - 02-10-2018

(02-09-2018, 01:03 AM)Ankur Wrote: This is a good question.

I am sure there can be multiple way to solve this. Here is one of the solutions I created for you.  You just need to call ALL the delimiters you use in the string and the custom SplitExtended function will do the rest.

Essentially I am using the built in Replace function to run n times where n is the number of delimiters you supply in the array.

Code:
Function SplitExtended (sPhraseFn, aDelimiters)
'Find total number of delimiters. Remember ubound starts from 0 index    
iNoOfDelimiters = UBound(aDelimiters)

'Replace all your delimiters with space      
For Iterator = 0 To iNoOfDelimiters
sPhraseFn = Replace (sPhraseFn, aDelimiters(Iterator)," ")    
Next    

SplitExtended = sPhraseFn
End Function

sPhrase = "My?name/isNandha-welcome^"
sPhraseClean = SplitExtended(sPhrase, Array("?","/","-","^"))
msgbox sPhraseClean
Wow!!!

thanks alot Ankur..