SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    Afrika
    Join Date
    Jul 2004
    Location
    Nigeria
    Posts
    1,737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do i test to see if a comma is present ?

    hello,
    I am using this code below to count the number of variables after the comma

    Code:
    jumvar = 43352352,325324452,235234452,24523454
    jumvarsplt = split(jumvar,",")
    valnum = CInt(ubound(jumvarsplt))
    But i would like to know how to test if the variable has a comma before running the above code.

    how do i achieve this efficiently

    rgds
    Afrika

  2. #2
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Easy...

    Code:
    dim x
    searchIn = "XXX,XX"
    searchFor = ","
    
    If InStr(searchIn,searchFor) Then
    'do whatever
    end if

  3. #3
    Afrika
    Join Date
    Jul 2004
    Location
    Nigeria
    Posts
    1,737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I dont receive replies to my post again, i wonder whats wrong

    thanks Rhythm

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just so you know,
    Running split on something that has no delimiters (commas in your case) will product an array with 1 element, so it will still work for most purposes.

    aTest = Split("blah", ",")

    For i = 1 to UBound(aTest)
    response.write aTest(i)
    Next

    result ->> blah

  5. #5
    Afrika
    Join Date
    Jul 2004
    Location
    Nigeria
    Posts
    1,737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So taht means that using aTEST(i) or aTest(0) woudl be the same ?

    how can i get it to produce all the numbers, within the spilt

  6. #6
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    ca
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vbscript arrays are "0" based. Meaning the first array element starts at index 0.

    hence:
    for i = 0 to ubound(YourArray)
    'blah blah blah
    next

    Quote Originally Posted by jimfraser
    Just so you know,
    Running split on something that has no delimiters (commas in your case) will product an array with 1 element, so it will still work for most purposes.

    aTest = Split("blah", ",")

    For i = 1 to UBound(aTest)
    response.write aTest(i)
    Next

    result ->> blah

  7. #7
    Afrika
    Join Date
    Jul 2004
    Location
    Nigeria
    Posts
    1,737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    guess u mean

    aTest = Split("blah", ",")

    For i = 0 to UBound(aTest)
    response.write aTest(i)
    Next

    result ->> blah
    works better that way, since we are starting form 0 in the array

    thanks for you help

  8. #8
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oops, yep, my mistake

  9. #9
    Afrika
    Join Date
    Jul 2004
    Location
    Nigeria
    Posts
    1,737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks anyway

    Afrika


Bookmarks

Posting Permissions

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