Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts

    Split() - no delimeter

    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"?

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    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.
    OracleGuy

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    in javascript when using split("") - with an ampty delimiter string it splits on every character

    "abc".split("");
    I am the luckiest man in the world

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    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"
    </script>
    <%
    vbArr = split(jsArrStr,",")
    for i = 0 to ubound(vbArr)
    response.write "item" & i & "=" & vbArr(i) & "<br>"
    next
    %>

    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.

  • #5
    Regular Coder
    Join Date
    Oct 2003
    Location
    London, UK
    Posts
    411
    Thanks
    0
    Thanked 1 Time in 1 Post
    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:
    Code:
    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)
        Next
    
        SplitIntoChars = ArrayOutput
    End Function
    Marcus Tucker / www / blog
    Web Analyst Programmer / Voted SPF "ASP Guru"

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    who said my first script interpreter is not JScript?
    I am the luckiest man in the world

  • #7
    Regular Coder
    Join Date
    Oct 2003
    Location
    London, UK
    Posts
    411
    Thanks
    0
    Thanked 1 Time in 1 Post
    Originally posted by Roelf
    who said my first script interpreter is not JScript?
    Nobody did! But ghell (and glenngv) seem to be using VBScript!

    Marcus Tucker / www / blog
    Web Analyst Programmer / Voted SPF "ASP Guru"

  • #8
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    i couldn't tell that from ghell's post

    but enough with the jokin'around

    your solution should work fine
    I am the luckiest man in the world

  • #9
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Roelf, how could you not tell he was using VBScript from that post?

    Your psychic internet abilities are slipping, man.

    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!!!
    Last edited by whammy; 12-25-2003 at 02:48 AM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #10
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    sorry i didnt answer sooner, i was in mediera

    neway
    merry xmas whammy, happy new year too

    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

    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •