Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Split each character of a string in an array

 
Logged in as: Guest
arrSession:exec spGetSession 2,16,26550
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Post a VBScript >> Split each character of a string in an array
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Split each character of a string in an array - 9/29/2005 9:07:16 AM   
  Fredledingue


Posts: 370
Score: 0
Joined: 5/9/2005
From:
Status: offline
AFAIK, in VBS, it's not possible to split each character one by one with the "Split" method. Here is a work around:

'---example of text string: t---
t="abcdef"
'
'-----get text lenght-----
x=Len(t)
'---automaticaly Dim'ing the array while we don't know the number of items---
Execute "Dim c(" & x & ")"
'----populate the array-----
For i=0 To x
c(i)=Mid(t,i+1,1)
Next
'
'---That's it---
'---Now, view the result in message box (or do something else with it)-----
'
i=0
Do Until c(i)=""
MsgBox c(i)
i=i+1
Loop


< Message edited by Fredledingue -- 9/29/2005 9:08:46 AM >


_____________________________

Fred
 
 
Post #: 1
 
 RE: Split each character of a string in an array - 12/21/2005 6:20:51 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Here is a Regex way. It generates a collection of match objects instead of an array, but the result is essentially the same.

Set oRE = New Regexp
oRE.Pattern = "."
oRE.Global = True
theString= "This*&(*&^%is_                          The&^%&^%><><.,.,.,';';';  String"
Set colMatches = oRE.Execute(theString)
For Each oMatch In colMatches
    WScript.Echo oMatch.Value
Next

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Fredledingue)
 
 
Post #: 2
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Post a VBScript >> Split each character of a string in an array Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts