Substring error message
Author |
Message |
Adalias
|
Posted: Thu Jan 11, 2007 10:58 am Post subject: Substring error message |
|
|
I am making a word processor program that takes in a chunk of text and justifies it left, center, right, full, and snake (like a newspaper). I haven’t gotten very far but here’s what I’ve got:
code: |
var justification, line, current : string := ""
var col, istart, jstart : int := 1
istart := 1
jstart := 1
put "What type of justification do you want?"
put "left, center, right, full or snake?"
get justification
if justification = "left" or justification = "right" or justification = "full" or justification= “center” then
put "What length of line would you like?"
get col
end if
if justification = "left" then
put "Enter the line you would like to justify"
get line : *
for i : istart .. length (line)
for j : jstart .. length (line)
if line (j) = " " then
if (length (current) + length (line (i .. j))) <= col then
current := current + line (i .. j)
istart := j
exit
else
put current
current := ""
put ""
end if
end if
end for
end for
end if
|
I know you're probably seeing a lot of errors and ways to make it better and whatnot, but all I need help with is this one error. Run it the way it is and it will work, asking for the type of justification (left is the only one I've got atm) and length of the lines (I use 20), but right after entering the line it crashes with the error:
Left bound of substring exceeds right by more than 1.
While highlighting line 18
if (length (current) + length (line (i .. j))) <= col then
I'm sure there is a very simple answer to this problem but try as I might I just can't seem to find it. Any help would be appreciated |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Ultrahex
|
Posted: Thu Jan 11, 2007 9:53 pm Post subject: Re: Substring error message |
|
|
your instructions on how to use the program were not very well
i was confused about what it meant by
"Enter the line you would like to justify" anyhow...
Ok, the problem occurs because you cant have 20 lines of text for a sentence that is only 20 long.
or something like that, you are trying to justify it left???
Turing: | var justification, line, current : string := ""
var col, istart, jstart : int := 1
var isEOL : boolean := false
istart := 1
jstart := 1
put "What type of justification do you want?"
put "left, center, right, full or snake?"
get justification
if justification = "left" or justification = "right" or justification = "full" or justification = "center" then
put "What length of line would you like?"
get col
end if
if justification = "left" then
put "Enter the line you would like to justify"
get line : *
for j : 1 .. length (line )
if j mod col = 0 or isEOL = true then
isEOL := true
if line (j ) = " " then
put ""
isEOL := false
else
put line (j ) ..
end if
else
put line (j ) ..
end if
end for
end if |
That is how i would attempt to do, BTW i made it so it writes that last word still and when it gets to next space it goes to next line, however you could do it the otherway and backtrace. |
|
|
|
|
|
Clayton
|
Posted: Thu Jan 11, 2007 10:14 pm Post subject: Re: Substring error message |
|
|
Your error means that the left or lower bound of your substring (the length(current (i..j))) is greater than the upper or right bound of the substring. In other words, i becomes higher than j, and that's not good, I think you want to have it the other way around ( length(current(j..i)) ) |
|
|
|
|
|
[Gandalf]
|
Posted: Fri Jan 12, 2007 6:11 pm Post subject: RE:Substring error message |
|
|
Or alternatively and more flexibly:
|
|
|
|
|
|
Adalias
|
Posted: Wed Jan 17, 2007 2:09 pm Post subject: Re: Substring error message |
|
|
Thanks Ultrahex that helped alot. |
|
|
|
|
|
|
|