
-----------------------------------
sockoo
Wed Jun 21, 2006 4:35 pm

String manipulation
-----------------------------------
Alright so i want to Manipulate a string by writing it backwards

for example : a program that spells Night like this :
t
th
thg
thgi
thgin

So far this is what i'v come up with : 
var sentence : string
sentence := "Night"
for decreasing i : length(sentence) .. 1
        put sentence (i)
end for 


-----------------------------------
Clayton
Wed Jun 21, 2006 4:39 pm


-----------------------------------
put a ".." after your "put sentence (i)", this just causes the next input/output using put or get to occur on the same line :D

-----------------------------------
aldreneo
Wed Jun 21, 2006 4:50 pm


-----------------------------------

var word1:string
var word: flexible array 1 .. 0 of string
put "Enter a word: "..
get word1
for decreasing i : length(word1) .. 1
new word, upper (word) + 1
word(upper(word)) := word1(i)
end for
for i : lower (word) .. upper (word)
put word(i) ..
end for
[/code]

-----------------------------------
sockoo
Wed Jun 21, 2006 6:51 pm


-----------------------------------
put a ".." after your "put sentence (i)", this just causes the next input/output using put or get to occur on the same line :D

Ideally this is what im looking for except i'd like to see each step the program has gone through for it to reach its ending of spelling the word backwards.

I want it to spell the word backwards one letter at a time.

-----------------------------------
aldreneo
Wed Jun 21, 2006 7:04 pm


-----------------------------------
Here you are:

var word1 : string
var worda : flexible array 1 .. 0 of string
put "Enter a word: " ..
get word1
for decreasing i : length (word1) .. 1
    new worda, upper (worda) + 1
    worda (upper (worda)) := word1 (i)
    for b : lower (worda) .. upper (worda)
        put worda (b) ..
    end for
    put ""
end for
[/code]

-----------------------------------
TheOneTrueGod
Wed Jun 21, 2006 7:37 pm


-----------------------------------
Don't do peoples work for them.  It doesn't help them at all.

Anyways, strings can be concatenated using the + operator.

var a : string := "Hello"
a := a + " "
a += "World"
a := "I would like to say, " + a
put a

(untested)

That should help you out in string management.

-----------------------------------
sockoo
Wed Jun 21, 2006 9:16 pm


-----------------------------------
Don't do peoples work for them.  It doesn't help them at all.



I Agree!!  , And Thank You! 

Also Thank you for ur help Aldreneo but i'v created my own source code with less lines than your's :)


var sentence : string := "simple"
var nothing : string := " "
for decreasing i : length (sentence) .. 1
    nothing += sentence (i)
    put nothing
end for


-----------------------------------
MysticVegeta
Thu Jun 22, 2006 12:38 am


-----------------------------------
You know to add a string to another string, it doesnt have to have some character in it, the "nothing" string could also be "" instead of " " to begin with.

-----------------------------------
aldreneo
Thu Jun 22, 2006 8:51 am


-----------------------------------
Ya, but try putting a GIANT  300 charictor thing..It says "string to long"

Mine supports that :D

If you would ever need that

-----------------------------------
[Gandalf]
Thu Jun 22, 2006 11:29 am


-----------------------------------
OK, but I must point out why that is incorrect reasoning.  In your version, you're starting out with a string, so the reversed string is only going to be as long as the original.  Now, if you were going to get an error for concatenating too many characters to the string (when reversing it), you would have gotten the same error for originally declaring the string with too many characters.  So there's really no point to using a flexible array since the original string is limited by the 255 character maximum.

-----------------------------------
aldreneo
Thu Jun 22, 2006 12:30 pm


-----------------------------------
"]OK, but I must point out why that is incorrect reasoning.  In your version, you're starting out with a string, so the reversed string is only going to be as long as the original.  Now, if you were going to get an error for concatenating too many characters to the string (when reversing it), you would have gotten the same error for originally declaring the string with too many characters.  So there's really no point to using a flexible array since the original string is limited by the 255 character maximum.

Oh, right :oops:
