Jump to the post that solved this thread.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Split a string with multiple delimiters in VBScript
#1
Solved: 6 Years, 9 Months, 1 Week ago
How can i split the below string

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

Thanks
Reply
#2
Solved: 6 Years, 9 Months, 1 Week ago
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
Want to fast track your QTP/UFT Learning? Join our UFT Training Course
Reply
#3
Solved: 6 Years, 9 Months, 1 Week ago
(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..
Reply
Jump to the post that solved this thread.


Possibly Related Threads…
Thread Author Replies Views Last Post
  Split function in string nidhishnair 13 64,505 07-07-2020, 03:47 PM
Last Post: helmzshelmz
Question Split Function Chaithra N 0 1,160 12-18-2019, 11:33 AM
Last Post: Chaithra N
  Replace a string in a word document with another string rekha.naik 8 15,472 11-14-2013, 12:58 PM
Last Post: pranikgarg
  Split Function diya 2 5,743 11-28-2012, 08:49 PM
Last Post: diya
Question Deatils on Split action with Nested type sams001 0 3,356 10-30-2012, 03:03 PM
Last Post: sams001

Forum Jump:


Users browsing this thread: 2 Guest(s)