substring problems for java noobie

From: Don Freeman (freemand_at_sonic.net)
Date: 12/02/04


Date: Thu, 02 Dec 2004 01:16:17 GMT

Seems like whatever value I use for the first int field (starting position)
the substring procedure negates it and triggers a String index out of range
error.

I've tried all sorts of work arounds to no avail, am I defining the two
string variable incorrectly?

code snippet:

String lastChar = new String();
String imageDir = new String();
<...>
System.out.println(imageDir); //debug = C:\images\
  //ok so far but:
lastChar = imageDir.substring(2,1);
  //triggers: String index out of range: -1: -- this value is always the
negated value +1 of the of the starting position value.

I'm starting to lose hair over this so any help will also help keep my
barber in business.

Thanks,
Don Freeman



Relevant Pages

  • Re: problem w/conditional...
    ... Sorry, I missed it, and I notice you are printing the stacktrace. ... I notice you are printing the 'found phrase' as well as ... is supposed to happen at the beginning and end of the String? ... java.lang.StringIndexOutOfBoundsException: String index out of range: -1 ...
    (comp.lang.java.help)
  • Re: can someone please take a look at this(pretty basic)
    ... vamp4l wrote: ... parse that string and pass each integer to a vector...heres the method im trying to use... ... string index out of bounds exception for the line ...
    (comp.lang.java.programmer)
  • Re: $request problem
    ... Not quotes a string index generates an E_NOTICE or something, ... Not quoting the string index is generally bad form. ... Single quotes provide a small performance gain as php doesn't try to ...
    (comp.lang.php)
  • Re: Ada.Strings.Bounded
    ... satisfaction has sharp boundaries that don't usually coincide with ... ordinary conceptual boundaries. ... But the Ada String type, with its padding, does not satisfy ... So you cannot exploit the limitation of the string index being Positive in ...
    (comp.lang.ada)
  • Re: access parent window object from inside iframe
    ... I would try it with only the string index into the forms collection: ... The second integer argument, iSubIndex, is (according to the ... Position of an element to retrieve. ...
    (microsoft.public.scripting.vbscript)