Results 1 to 3 of 3

Thread: Splitting variables

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    343
    Hello,

    I have a textbox where the user can enter keywords which he must
    "split" by using a comma. IE. forum,internet,webpage

    How can I split whatever he entered, into different, single keywords
    eg. he enters forum,internet,webpage - I now want to split it into
    var1="forum"
    var2="internet"
    var3="webpage"

    Any help please.

    Thanks,
    T

  2. #2
    Sadovod
    Guest
    Why don't you use split function ?

    stringObj.split([separator])


    function SplitDemo(){
    var s, ss;
    var s = "The rain in Florida falls mainly in the plain.";
    // Split at each space character.
    ss = s.split(" ");
    return(ss);
    }

  3. #3
    Fanatic Member Ianpbaker's Avatar
    Join Date
    Mar 2000
    Location
    Hastings
    Posts
    696
    Hi turfbult

    You can do the the following providing it is only a maximum of 3 words

    Code:
    Dim sVar1
    Dim sVar2
    Dim sVar3
    Dim sString
    Dim iCountFirst
    Dim iCountSecond
    
    sString = "forum,internet,webpage"
    iCountFirst = InStr(1, sString, ",")
    
    'more than one word
    If iCountFirst > 0 Then
        sVar1 = Mid(sString, 1, iCountFirst - 1)
        
        'More than two words
        If InStr(iCountFirst + 1, sString, ",") > 0 Then
            iCountSecond = InStr(iCountFirst + 1, sString, ",")
            sVar2 = Mid(sString, iCountFirst + 1, Len(sString) - iCountSecond + 1)
            sVar3 = Mid(sString, iCountSecond + 1)
        Else
            sVar2 = Mid(sString, iCountFirst + 1)
        End If
        
    Else
        sVar1 = sString
    End If
    Hope this helps

    Ian
    Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!

Posting Permissions

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



Click Here to Expand Forum to Full Width