Author |
Message |
sockoo
|
Posted: Wed Jun 21, 2006 4:35 pm Post subject: 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 :
code: | var sentence : string
sentence := "Night"
for decreasing i : length(sentence) .. 1
put sentence (i)
end for
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Clayton
|
Posted: Wed Jun 21, 2006 4:39 pm Post subject: (No subject) |
|
|
put a ".." after your "put sentence (i)", this just causes the next input/output using put or get to occur on the same line |
|
|
|
|
|
aldreneo
|
Posted: Wed Jun 21, 2006 4:50 pm Post subject: (No subject) |
|
|
code: |
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
|
Posted: Wed Jun 21, 2006 6:51 pm Post subject: (No subject) |
|
|
SuperFreak82 wrote: put a ".." after your "put sentence (i)", this just causes the next input/output using put or get to occur on the same line
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
|
Posted: Wed Jun 21, 2006 7:04 pm Post subject: (No subject) |
|
|
Here you are:
code: |
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
|
Posted: Wed Jun 21, 2006 7:37 pm Post subject: (No subject) |
|
|
Don't do peoples work for them. It doesn't help them at all.
Anyways, strings can be concatenated using the + operator.
code: | 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
|
Posted: Wed Jun 21, 2006 9:16 pm Post subject: (No subject) |
|
|
TheOneTrueGod wrote: 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
code: |
var sentence : string := "simple"
var nothing : string := " "
for decreasing i : length (sentence) .. 1
nothing += sentence (i)
put nothing
end for
|
|
|
|
|
|
|
MysticVegeta
|
Posted: Thu Jun 22, 2006 12:38 am Post subject: (No subject) |
|
|
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. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
aldreneo
|
Posted: Thu Jun 22, 2006 8:51 am Post subject: (No subject) |
|
|
Ya, but try putting a GIANT 300 charictor thing..It says "string to long"
Mine supports that
If you would ever need that |
|
|
|
|
|
[Gandalf]
|
Posted: Thu Jun 22, 2006 11:29 am Post subject: (No subject) |
|
|
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
|
Posted: Thu Jun 22, 2006 12:30 pm Post subject: (No subject) |
|
|
[Gandalf] wrote: 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 |
|
|
|
|
|
|