NEEH HELP...simple string manipulation

Discussion in 'Javascript' started by Goran Petrovic, Jul 23, 2003.

  1. I wrote a vb function, but i need it i jaavscript..i know java sintax but am
    not sure how to make it work. this extracts teh file name from a path...i
    thought strcpy..or something..but dont really know. Please help

    function GetWriterName

    str=document.location

    for i = len(str) to 1 step -1
    if mid(str,i,1)="/" then
    str= mid( mid(str,i+1,100),1,len( mid(str,i+1,100))-4)
    str="../../../aspx/quotes"+str+".aspx"
    GetWriterName="../../../aspx/quotes"+str
    exit function
    end if
    next

    end function


    Goran
    Goran Petrovic, Jul 23, 2003
    #1
    1. Advertising

  2. Goran Petrovic

    Philip Ronan Guest

    On 03.7.23 0:47 PM, Goran Petrovic wrote:

    > I wrote a vb function, but i need it i jaavscript..i know java sintax but am
    > not sure how to make it work. this extracts teh file name from a path...i
    > thought strcpy..or something..but dont really know. Please help


    To extract the filename from the current location, you could use something
    like this:

    thisPage = location.pathname.substr(location.pathname.lastIndexOf('/')+1);

    Is that what you were after?

    Phil

    --
    Philip Ronan

    (Please remove the "z"s if replying by email)
    Philip Ronan, Jul 23, 2003
    #2
    1. Advertising

  3. "Goran Petrovic" <> writes:

    > I wrote a vb function, but i need it i jaavscript..i know java sintax but am


    It will help you slightly, but Javascript is not Java. Their syntaxes
    are similar, but not equal.

    > not sure how to make it work. this extracts teh file name from a path...i
    > thought strcpy..or something..but dont really know. Please help


    > if mid(str,i,1)="/" then
    > str= mid( mid(str,i+1,100),1,len( mid(str,i+1,100))-4)
    > str="../../../aspx/quotes"+str+".aspx"
    > GetWriterName="../../../aspx/quotes"+str


    Do you really mean this? The result will be

    "../../../aspx/quotes../../../aspx/quotes"+filename+".aspx;

    I don't even think there is a "/" in front of the filename.
    I guess one of them are superflous.

    A solution:
    ---
    function getWriterName() {
    var str = location.pathname; // easier than working with full href.
    for (var i = str.length ; i > 0 ; i--) {
    if (str.charAt(i)=="/") {
    str = str.substring(i+1); // no second argument means until end of string
    return "../../../aspx/quotes/"+str+".aspx";
    }
    }
    }
    ---
    Now for the easier way:
    ---
    function getWriterName() {
    var str = location.pathname;
    var i = str.lastIndexOf("/");
    return "../../../aspx/quotes"+str.substring(i)+".aspx";
    }
    ---
    Good luck.
    /L
    --
    Lasse Reichstein Nielsen -
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
    'Faith without judgement merely degrades the spirit divine.'
    Lasse Reichstein Nielsen, Jul 23, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dd711
    Replies:
    6
    Views:
    882
    Alex Hunsley
    Oct 1, 2004
  2. Replies:
    3
    Views:
    410
  3. morc

    String manipulation help.

    morc, Mar 6, 2006, in forum: Java
    Replies:
    5
    Views:
    354
    Oliver Wong
    Mar 7, 2006
  4. jeff
    Replies:
    1
    Views:
    318
    Andreas Kuntzagk
    Aug 1, 2003
  5. Rex
    Replies:
    2
    Views:
    294
Loading...

Share This Page