Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

break up a string

Status
Not open for further replies.

cjkenworthy

Programmer
Sep 13, 2002
237
0
0
GB
I just have a standard variable:

dim vartext
vartext = "value"

Is there any way to split this string into an array, where each element in the array is a character from the string such that:

MyArray(0) = "v"
MyArray(1) = "a"
MyArray(2) = "l" etc ...

Any ideas?
 
dim MyArray()

redim preserve MyArray(len(vartext))

for i=1 to len(vartext)
MyArray(i)=mid(vartext,i,1)
next

MyArray(0) will be empty so when accessing the values in the array start at (1) "did you just say Minkey?, yes that's what I said."

MrGreed
 
Another way would be.

myArray = array("v", "a", "i")

or Create a long string via a loop (this avoids redim etc)

myString = "s, p, l, i, t, m, e"

myArray = split(myString, ",")

myArray will now have 7 elements.

Hope that helps.

Chuckster1

 
<SCRIPT LANGUAGE=vbs>
dim vartext, letterArray
vartext = &quot;value&quot;

letterArray = split(varText, &quot;&quot;)

for i = 0 to uBound(letterArray)
document.write letterArray(i)
next
</script> -- Just trying to help...
[wolf]<--- This is a wolf? We need a new icon.......
mikewolf@tst-us.com
 
But that simply reads the whole string into the first element of the array .
 
I'm sorry cjkenworthy, you are right. The split function in javascript does work with the &quot;&quot; delimeter and puts each letter in separately. Apparently, vbScript doesn't have the same feature. I mistakenly thought that they would behave similarly. -- Just trying to help...
[wolf]<--- This is a wolf? We need a new icon.......
mikewolf@tst-us.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top