View Full Version : Split() - no delimeter

12-17-2003, 09:22 PM
well, i know u can split like "a,b,c" into "a","b","c" using "," as the delimeter, but is there any way to split "abc" into "a","b","c"?

12-18-2003, 12:34 AM
I don't think so, you'd prolly need to write a function to do that. Would it always be a single character that you'd want to seperate out? If so, it would be pretty easy to write a loop to do that.

12-18-2003, 07:34 AM
in javascript when using split("") - with an ampty delimiter string it splits on every character


12-18-2003, 08:32 AM
So, use server-side javascript in conjunction with vbscript:

<script language="javascript" runat="server">
var str = "abc";
var jsArrStr = str.split("").toString(); //returns "a,b,c"
vbArr = split(jsArrStr,",")
for i = 0 to ubound(vbArr)
response.write "item" & i & "=" & vbArr(i) & "<br>"

You cannot assign a js array directly into a vbscript array so string representation of the js array is needed, thus the .toString() bit. Although it is not required since if you do a vbscript split of a js array, the specified js array is implicitly turned into a string. But it's better to explicitly turn it into a string.

12-20-2003, 12:54 PM
Why bother with all that? Simply loop through the strip character-by-character like OracleGuy suggested it's by far the easiest, probably a little quicker, and doesn't require ASP to load a second script interpreter.

Untested code follows:
Function SplitIntoChars(StringInput)
Dim ArrayOutput(), StringLen, N

StringLen = Len(StringInput)
ReDim ArrayOutput(StringLen - 1)

For N = 0 To StringLen - 1
ArrayOutput(N) = Mid(StringInput, N + 1, 1)

SplitIntoChars = ArrayOutput
End Function

12-22-2003, 10:23 PM
who said my first script interpreter is not JScript?

12-24-2003, 09:41 PM
Originally posted by Roelf
who said my first script interpreter is not JScript? Nobody did! But ghell (and glenngv) seem to be using VBScript!

:p :D

12-24-2003, 11:09 PM
i couldn't tell that from ghell's post :p

but enough with the jokin'around

your solution should work fine

12-25-2003, 03:44 AM
Roelf, how could you not tell he was using VBScript from that post?

Your psychic internet abilities are slipping, man. :p

Anyway, moot point, either way works, or you could write it entirely in JScript and hopefully use its advantages over VBScript since Microsoft did seem to keep the majority of advantages of JavaScript in their interpretation... I might start doing that more often since it's just cleaner. The only problem with that approach is when you DO run into a problem, there is little to no documentation (that I have been able to find anyway) on server-side JScript, so you have to spend time experimenting. :)

By the way, Happy Holidays, everyone!!!

12-29-2003, 06:42 PM
sorry i didnt answer sooner, i was in mediera :(

merry xmas whammy, happy new year too :D

btw.. its slightly obvious i wanted vbscript, "opment > ASP > Split() - no d" asp..if i wanted javascript i would just put it in there lol :p

anyway, i am just trying to do a sorta hashing algorithm type thingie... its not anything to do with hashing tho, its just sorta encrypting a password and unencrypting it afterwards so that my m8s "steal their coockie for my site and take their password from it" program will not work because what he will get out of the cookie will be jibberish, i could maby do it with replaces now i think about it, if i put a loop or just plain 26 or 52 lines of replaces

it cant really go client side because of the security and it cant redirect or anything because it has to run in the background, ill try the replaces though, now i have had so much time to think about it :p