Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > NEEH HELP...simple string manipulation

Reply
Thread Tools

NEEH HELP...simple string manipulation

 
 
Goran Petrovic
Guest
Posts: n/a
 
      07-23-2003
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


 
Reply With Quote
 
 
 
 
Philip Ronan
Guest
Posts: n/a
 
      07-23-2003
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.lastInd exOf('/')+1);

Is that what you were after?

Phil

--
Philip Ronan
http://www.velocityreviews.com/forums/(E-Mail Removed)
(Please remove the "z"s if replying by email)


 
Reply With Quote
 
 
 
 
Lasse Reichstein Nielsen
Guest
Posts: n/a
 
      07-23-2003
"Goran Petrovic" <(E-Mail Removed)> 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 - (E-Mail Removed)
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
String manipulation Chris ASP .Net 1 05-24-2004 02:19 PM
Advanced String Manipulation (C#) Aaron ASP .Net 2 01-02-2004 06:50 PM
String Manipulation Aaron ASP .Net 3 12-31-2003 03:39 PM
Perl string manipulation jared in ecs Perl 2 10-22-2003 05:36 PM
String Array Manipulation Problem Garfield ASP .Net 5 08-27-2003 10:07 PM



Advertisments