aspose file tools*
The moose likes Beginning Java and the fly likes Problems manipulating string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problems manipulating string" Watch "Problems manipulating string" New topic
Author

Problems manipulating string

nick angel
Ranch Hand

Joined: Dec 14, 2005
Posts: 39
Hello to everyone. I have a little problem manipulating a string.

The initial string is as follows:

String line='javascriptpen_win(\'https://client.vmbl.ca/popvmbl55/client/\');';

What I need to do is retrieve a string does not contain the ' in the beginning and the end. I tried the following unsuccessfully:

line = (line.replace('\'', ' ')).trim();
line = line.substring(0, line.length() - 1);
if (line.indexOf("javascript") > 0) {
line = line.replace(' ', '\'');
}

I obtain the following:

javascriptpen_win(\ https://client.vmbl.ca/popvmbl55/client/\ ); (spaces are still left behind without the ' after the \).

I do not if it helps but this line will eventually be used in an html document.

Thank you for your help

[ EJFH: Turn off smilies ]
[ December 21, 2005: Message edited by: Ernest Friedman-Hill ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

Is this Java code, JavaScript, or something else? You're using single quotes in a way which is illegal in Java. We can't really help without knowing what language you're writing in, and seeing the exact, correct code in question.


[Jess in Action][AskingGoodQuestions]
Martin Mathis
Ranch Hand

Joined: Dec 20, 2004
Posts: 45
How about using something like the following (no, I didn't actually test it). It seems like the replacing is just making things overly complicated.

Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
I assume you are trying to convert the Java String containing:



into a String containing this:



If so, you could always try substring() between the first occurrence of ' (using indexOf()) and the last occurrence of ' (using lastIndexOf()).

If I've misunderstood, please set the question in context...
[ December 21, 2005: Message edited by: Charles Lyons ]

Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problems manipulating string
 
Similar Threads
While replacing char of soap response then it throws error
Returning arrayList and Final line value alone getting printed in jsp
Applet Server communication for SAX Parser Delaying the process
save a xml file using java
Modify Newline character in java