Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems manipulating string

 
nick angel
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Martin Mathis
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic