Web Design and Development Forums

Substring Problem

This is a discussion on "Substring Problem" within the Java, JSP, Cold Fusion section. This forum, and the thread "Substring Problem are both part of the Program Your Website category.

Old Aug 16th, 2007, 10:01   #1 (permalink)
New Member
 
Join Date: Aug 2007
Location: Ireland
Posts: 3
Post Substring Problem

Hi
I pretty new to this, but I need help badly. I'm using a browse button on a html page which selects a file. The file is not for upload I just require the path. What I want to be able to do is crop the file path from the last backslash and replace it with text of my choice.
eg
file path - D:\tomcat\webapps\mailer2\home.jpg
do to - D:\tomcat\webapps\mailer2\
result - D:\tomcat\webapps\mailer2\logo.jpg

I think it might be done with the substring function but I really dont know. I cant figure it out from the docs. Any help would be great thanks!
Cheers
Daithi
daithi is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Aug 24th, 2007, 01:32   #2 (permalink)
Up'n'Coming Member
 
Join Date: Aug 2006
Location: Peru
Age: 21
Posts: 52
Re: Substring Problem

Hi there:
Well, it's not that hard to do, but there are some issues that you might take into consideration.
First, since you're designing a web, you should considerate other user might use a different operating system (like from the Unix family) and the path to files on those other systems is different from that weird one on windows. For example if the path comes from a Linux machine, you won't be looking for a backslash, but for a simple slash.
The second thing is: where do you want to do this file-cropping? Is it server-side or client-side? and if server-side, what language are you using? With this info I could give you the code so you can do the cropping you want.

Waiting for your response...
QuikFrozen is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Aug 24th, 2007, 07:53   #3 (permalink)
New Member
 
Join Date: Aug 2007
Location: Ireland
Posts: 3
Re: Substring Problem

The web app is going to be exclusively used within an intranet in a company. Therefore its safe to assume that all the users are Windows based. To answer your second question, ideally the browse cropping is taking place client side. Java/Javascript is the coding language used. I've been looking for a solution for this for quite a while, any help would be great.
Thanks
daithi is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Aug 28th, 2007, 14:02   #4 (permalink)
Up'n'Coming Member
 
Join Date: Aug 2006
Location: Peru
Age: 21
Posts: 52
Re: Substring Problem

Ok man, here's a small javascript I just wrote with a little html so you realize what's happening :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Backslash</tilte>
<script type="text/javascript">
function doCrop(text){
var file=document.getElementById("myfile").value;
if(file!=""){
crop(file,text);
}
else{
alert("must select a file");
}
}
function crop(file,newText){
var slash;
var temp=file.indexOf("\\");
//get the last backslash
while(temp>=0){
slash=temp+1;
temp=file.indexOf("\\",slash);
}
if(slash>=0){
//here you can do whatever you want to the path
file=file.substring(0,slash)+newText;
alert(file);
}
else{
alert("bad file format");
}
}
</script>
</head>
<body>
<input type="file" id="myfile" />
<input type="button" name="mybutton" value="Go" onclick="doCrop('main.jsp');"/>
</body>
</html>
QuikFrozen is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Aug 30th, 2007, 12:15   #5 (permalink)
New Member
 
Join Date: Aug 2007
Location: Ireland
Posts: 3
Talking Re: Substring Problem

Cheers for that works a treat. I made one slight adjustment just so you know.
I changed the method getElementById to getElementsByName. It seems to work better.
Thanks again!
daithi is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
browse, java, modify text, substring

Thread Tools
Rate This Thread
Rate This Thread:

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 On

Similar Threads
Thread Thread Starter Forum Replies Last Post
First image problem and inline list problem konnor5092 CSS Forum 8 Dec 1st, 2007 09:08
SUBSTRING in query contiw MSSQL & Access 0 Oct 11th, 2006 19:23



Latest Updates

All Points SEO Security Advisory - CHECK YOUR SITE NOW!

Creative Coding :: February 2008

Webforumz is sponsored by: WESH UK Web Hosting
All times are GMT. The time now is 23:01.

Sleep Study Scoring :: Free Bet :: Website Templates :: Online Betting :: Bookmakers :: Funny Quotes :: Internet Recruitment Software :: Microsoft CRM Experts :: Online Casino :: Decorated Christmas Trees :: Midwife Forums :: Football Betting :: Ecommerce Software :: Web Hosting :: Football Stats :: Dry Cleaning Collection :: xtreme wales - extreme clothing :: Apuestas :: Sharepoint Consultants :: Website Optimisation :: Office Clearance London :: Sharepoint Experts :: Sports Betting :: Casino :: Website Templates :: Web Design Development India :: Online Gambling

Powered by: vBulletin Version 3.7, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
© 2003-2008 Webforumz.com : All Rights Reserved
Search Engine Friendly URLs by vBSEO 3.2.0 RC6


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59