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 5 of 5
  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    94
    Thanks
    4
    Thanked 0 Times in 0 Posts

    could someone teach me how to modify a string

    i have a variable that looks like this
    9/thumb1.png?=38255

    the first number could range from 1 to 33
    could someone explain how to get the first value before the forward slash into a variable.
    so in this case it would be '9'
    but could be ''33'

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Google "javascript split". Split the value using / as the delimiter. The first position (position 0, not 1) will be the number you are seeking.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #3
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,341
    Thanks
    260
    Thanked 32 Times in 31 Posts
    does it have to be using js, you can do it with php really easy using explode here is the link http://php.net/manual/en/function.explode.php

    im not sure really how to do this with js either but you might want to check out regex stuff i think thats what you want to use.

    http://www.regular-expressions.info/



    UPDATE: cool wolfshade i learned something today already, nice

  • #4
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    here's a simple example

    Code:
    function myFunc(string) {
    var a = []
    a= string.split('/')
    alert(a[0])
    }

  • Users who have thanked DanInMa for this post:

    gerble1000 (10-02-2012)

  • #5
    New Coder
    Join Date
    Nov 2011
    Posts
    94
    Thanks
    4
    Thanked 0 Times in 0 Posts
    cheers guys just downloaded a pdf on it.
    and the example worked great


  •  

    Posting Permissions

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