LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-30-2009, 05:16 AM   #1
Completely Clueless
Member
 
Registered: Mar 2008
Location: Marbella, Spain
Distribution: Many and various...
Posts: 896

Rep: Reputation: 70
Question Javascript string search query


Hi all,

I've been tring to get this Javascript function:

str.indexOf()

To report the first instance of a predetermined string in a text file, but am having no luck. I know this command is good for literal strings in isolation, but is there no way it can be made to scan an actual file? If not, what command should I be using?

Thanks.

Last edited by Completely Clueless; 09-30-2009 at 05:19 AM.
 
Old 09-30-2009, 08:43 AM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
how are you getting the file details into your string?
 
Old 09-30-2009, 11:20 AM   #3
Completely Clueless
Member
 
Registered: Mar 2008
Location: Marbella, Spain
Distribution: Many and various...
Posts: 896

Original Poster
Rep: Reputation: 70
Quote:
Originally Posted by graemef View Post
how are you getting the file details into your string?
Here's the relevant code snippet:
Code:
<script type="text/javascript">
var str="/home/clueless/documents/textfile.txt";
document.write(str.indexOf("searchterm") + "<br />");
</script>
I've also tried escaping the forward slashes with an extra slash and with and without the quotes, but no joy. It just always seems to interpret

/home/clueless/documents/textfile.txt as a literal string rather than a path to the named file.

Last edited by Completely Clueless; 09-30-2009 at 11:20 AM. Reason: missing code tags!
 
Old 09-30-2009, 12:20 PM   #4
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
Code:
function findocur(var what, var string){
var base = 0;
var tick = 0;
var flag = 0;
for(base = 0;base < string.length;base++){
flag = 1;
for(tick = 0;tick < what.length;tick++){
if(string[base + tick] != what[tick]){flag = 0; break;}
}
if(flag){return base;}
}
return -1;
}
that should do it but my javascript skills are rusty
 
Old 09-30-2009, 02:59 PM   #5
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,774

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Standard Javascript doesn't support file IO, since it would let web sites do nasty things on your computer.
 
Old 09-30-2009, 05:21 PM   #6
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
the original poster said nothing about file io
 
Old 09-30-2009, 06:24 PM   #7
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,774

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by smeezekitty View Post
the original poster said nothing about file io
The original poster asked

Quote:
Originally Posted by Completely Clueless (emphasis added)
but is there no way it can be made to scan an actual file?
 
Old 09-30-2009, 06:39 PM   #8
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
true
javascript cannot do server or client file io
if you need it move to PHP
 
Old 10-02-2009, 01:00 PM   #9
Completely Clueless
Member
 
Registered: Mar 2008
Location: Marbella, Spain
Distribution: Many and various...
Posts: 896

Original Poster
Rep: Reputation: 70
Thanks, guys. I thought I was going nuts there for a minute!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
search string in text and print string wolfipa Linux - Software 4 09-17-2009 08:50 AM
Strange Firefox 3 behaviour with javascript search engine Gagarin Gambit Linux - Software 0 06-26-2008 06:43 PM
Can you make search ...search a string in a link....a url...a web address aus9 LQ Suggestions & Feedback 4 04-16-2008 09:37 AM
passing php string to javascript function djgerbavore Programming 2 03-01-2005 11:34 AM
C....Search a string for a string Scrag Programming 4 06-14-2004 04:15 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration