I can't seem to substring properly.
Author |
Message |
Helkain
|
Posted: Mon May 06, 2013 10:29 am Post subject: I can't seem to substring properly. |
|
|
What is it you are trying to achieve?
I am trying to break an inputted string down into individual words, by taking the index of the word for a space, and creating a new word from the previous index ( + 1) to the new index (- 1).
What is the problem you are having?
No matter how I look at this, I can't see how "The left bound of substring exceeds right bound by more than 1" -_-
Describe what you have tried to solve this problem
This has been a reocurring issue I've had for a while now. I have tried recreating the relevant code multiple times, from the ground up, using different variable configurations, and the result is always the same.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Turing: |
var word : string
var seperateWords : flexible array 1 .. 0 of string
var ind := 0
loop
exit when index (word (ind + 1 .. *), " ") = 0
new seperateWords, upper (seperateWords ) + 1
seperateWords (upper (seperateWords )) := word (ind .. index (word (ind + 1 .. *), " ") - 1)
ind := index (word (ind .. *), " ") + 1
end loop
|
Please specify what version of Turing you are using
Good ol' buggy 4.11
Thanks in advance oh benevolent code monkeys who inhabit this forum! |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Zren
![](http://compsci.ca/v3/uploads/user_avatars/1110053965512db6185954b.png)
|
Posted: Mon May 06, 2013 11:04 am Post subject: RE:I can\'t seem to substring properly. |
|
|
Try adding some debug output to figure out the values of your function calls. Eg:
Turing: |
var word : string := "glsadf afsg fdsg dsf gdsfg "
var seperateWords : flexible array 1 .. 0 of string
var ind := 0
loop
exit when index (word (ind + 1 .. *), " ") = 0
put "ind + 1 = ", ind + 1
put "word (ind + 1 .. *) = ", word (ind + 1 .. *)
put "index (word (ind + 1 .. *), \" \") = ", index (word (ind + 1 .. *), " ")
new seperateWords, upper (seperateWords ) + 1
seperateWords (upper (seperateWords )) := word (ind .. index (word (ind + 1 .. *), " ") - 1)
ind := index (word (ind .. *), " ") + 1
end loop
|
|
|
|
|
|
![](images/spacer.gif) |
|
|