• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problems manipulating string

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello to everyone. I have a little problem manipulating a string.

The initial string is as follows:

String line='javascript:open_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:

javascript:open_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 ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Author
Posts: 836
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic