SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    string inside another string

    Could anyone please tell me how to place a string inside of another string.

    For example, say I have the string www.url.com/url/ on my web page but I want the string to have a space added to it right before the url/ when the page loads, so that it now appears www.url.com/ url/

    Any help would be great.

    P.S. Don't worry about the onload stuff I just need to know how to concat a string inside of another string.

  2. #2
    SitePoint Addict jtrelfa's Avatar
    Join Date
    Oct 2004
    Location
    Troy, Mi
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Personally, I would use the substring and indexOf functionality in javascript to find the first instance of the single / in the url; then divide it into two strings:

    www.url.com/
    url/

    then concat the strings with a space
    www.url.com/ + " " + url

    http://www.w3schools.com/jsref/jsref_substr.asp

  3. #3
    SitePoint Evangelist borna's Avatar
    Join Date
    Jun 2006
    Location
    Iran, Tehran
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    substring

    As jtrelfa mentioned, The attribute substring(STRING,int a,int b) does the trick. something like,
    Code:
    substring(YOUR_STRING,1,THE_PLACE_YOU_MAY_BREAK)

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    borna, java is not the same thing as javascript

    please don't confuse the two!
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Evangelist borna's Avatar
    Join Date
    Jun 2006
    Location
    Iran, Tehran
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here, fortunately, the same ideas work. Thanks for your smart point.


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
  •