Author |
Message |
uberwalla
![](http://www.mac-help.com/images/starwars.gif)
|
Posted: Fri Nov 24, 2006 8:24 pm Post subject: i was wondering if... |
|
|
ok so i was wondering if it is possible to kinda "clean" a sentence in turing.
like im not talking encoding//decoding but... is there a way to take out all symbols and numbers etc from writing.
example:
u input something like "%h&i!Per^$son
and then it outputs "hiperson"
is that possible to do at all. i am interested cuz i want to make a game where the program inputs random letters, symbols, etc type thing and you have to decode type thing. it seems very lame, and yes it is but i want to do this for a start then id build on it after.
help would be very appreciated ! thx. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
jamonathin
![](http://compsci.ca/v3/uploads/user_avatars/57683465145f851a43dd9a.gif)
|
Posted: Fri Nov 24, 2006 8:57 pm Post subject: (No subject) |
|
|
Very possible. You are going to want to refer to ASCII codes. Basically ASCII links a value to each letter.
hit F10 in turing, search for "run window character set" and it will bring up a list of each value of each symbol/letter (character).
You will notice that the capital letters range from 65-90 and lower case letters range from 97-122.
Also look up chr and ord in turing help. You will also need string manipulation - help can be found in the Turing Walkthrough.
If you need help with it, post your code and we can help you out (without giving the answer ) |
|
|
|
|
![](images/spacer.gif) |
uberwalla
![](http://www.mac-help.com/images/starwars.gif)
|
Posted: Fri Nov 24, 2006 9:25 pm Post subject: (No subject) |
|
|
ok thx a bunch. i already new about the letter/number thing but im kinda wondering if its possible to do like.
if char not= x-x then
...
can x be the letters designated chr number? and have it asign that way then have it somehow remove the numbers? |
|
|
|
|
![](images/spacer.gif) |
jamonathin
![](http://compsci.ca/v3/uploads/user_avatars/57683465145f851a43dd9a.gif)
|
Posted: Wed Nov 29, 2006 11:42 pm Post subject: (No subject) |
|
|
uberwalla wrote: can x be the letters designated chr number? and have it asign that way then have it somehow remove the numbers?
Im not shure I fully understand what you're asking. The first question (before the and) makes me think your asking if you can reassign the value of the character to the value of 'x' - which is no. And then i dont know what you mean by 'removing the numbers'. ![Confused Confused](http://compsci.ca/v3/images/smiles/icon_confused.gif) |
|
|
|
|
![](images/spacer.gif) |
jamonathin
![](http://compsci.ca/v3/uploads/user_avatars/57683465145f851a43dd9a.gif)
|
Posted: Wed Nov 29, 2006 11:43 pm Post subject: (No subject) |
|
|
Also if you could clarify what this means
Quote:
if char not= x-x then
if char not= 0? |
|
|
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Thu Nov 30, 2006 1:02 am Post subject: (No subject) |
|
|
I think he's asking if he can do a check in that form to test whether char is within the range x to y, where x and y are his x and... x.
The answer is no.
uberwalla, you've already got a thread for this problem. Please explain why this extra topic was necessary, and how this topic is different (wasn't the question answered fully in your first topic?). |
|
|
|
|
![](images/spacer.gif) |
uberwalla
![](http://www.mac-help.com/images/starwars.gif)
|
Posted: Thu Nov 30, 2006 8:28 am Post subject: (No subject) |
|
|
o sry that was a later post when i half solved the problem then u helped meh thx though guys |
|
|
|
|
![](images/spacer.gif) |
ZeroPaladn
|
Posted: Thu Nov 30, 2006 9:06 am Post subject: (No subject) |
|
|
Cervantes wrote: I think he's asking if he can do a check in that form to test whether char is within the range x to y, where x and y are his x and... x.
The awnser is no.
The awnser is YES!
[code]for i : x .. y %just an example
if letter ~= i then
%put whatever happens here
end if
end for |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Clayton
![](http://compsci.ca/v3/uploads/user_avatars/1718239683472e5c8d7e617.jpg)
|
Posted: Thu Nov 30, 2006 11:20 am Post subject: (No subject) |
|
|
err no, if letter is a string, that code wont even run, but what Cervantes was saying that :
Cervantes wrote:
I think he's asking if he can do a check in that form
in which you cant. |
|
|
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Thu Nov 30, 2006 1:13 pm Post subject: (No subject) |
|
|
ZeroPaladn wrote: Cervantes wrote: I think he's asking if he can do a check in that form to test whether char is within the range x to y, where x and y are his x and... x.
The awnser is no.
The awnser is YES!
code: | for i : x .. y %just an example
if letter ~= i then
%put whatever happens here
end if
end for |
The answer is no, because of the restriction on form.
Now, you need to understand something about your code. It won't work anywhere close to the way it was designed to. Try tracing it, to see why.
Here's what happens. You start with i as x. If letter not= i, then we perform our action, A. Then i = x+1. If letter not= i+1, we do A. See where this is going? We are very likely going to perform A many times, even if letter does happen to be in the range x to y.
To code this properly, we use inequalities:
code: |
if letter < x or letter > y then
A
end if
|
|
|
|
|
|
![](images/spacer.gif) |
NikG
|
Posted: Thu Nov 30, 2006 2:45 pm Post subject: (No subject) |
|
|
There's an even easier solution than what everyone has talked about so far.
1. Create a string with all the letters (a-z, A-Z)
2. Create a for loop going through each character in the text where the symbols will be removed
3. Check whether each character is in the string (I believe the index function)
3. If the character is found, add it to a new string.
No need to mess with ascii tables or anything. |
|
|
|
|
![](images/spacer.gif) |
Clayton
![](http://compsci.ca/v3/uploads/user_avatars/1718239683472e5c8d7e617.jpg)
|
Posted: Thu Nov 30, 2006 3:41 pm Post subject: (No subject) |
|
|
yes, but then you are using up extra memory by creating that string variable to hold all of the acceptable characters, not something you want to do. |
|
|
|
|
![](images/spacer.gif) |
uberwalla
![](http://www.mac-help.com/images/starwars.gif)
|
Posted: Thu Nov 30, 2006 3:48 pm Post subject: (No subject) |
|
|
code: |
%The "Palindrome" Program
%By: Mike Lanthier
%Monday, November 28, 2006
function clean (x : string) : string
var CleanedWord := ""
for i : 1 .. length (x)
if x (i) >= chr (97) and x (i) <= chr (122) or x (i) >= chr (65) and x (i) <= chr (90) then
CleanedWord += x (i)
end if
end for
result CleanedWord
end clean
var word : string
var YesOrNo : string
var winID := Window.Open ("nobuttonbar")
loop
put "Enter a Word and I Will Remove Anything That Isn't A Letter."
get word
put clean (word)
put "\nTest Another Word? (Yes (y) Or No (n)?)"
get YesOrNo
exit when YesOrNo = "n"
cls
end loop
Window.Close (winID)
|
|
|
|
|
|
![](images/spacer.gif) |
zylum
![](http://compsci.ca/v3/uploads/user_avatars/1689129126468091c334ee0.gif)
|
Posted: Thu Nov 30, 2006 4:01 pm Post subject: (No subject) |
|
|
you can simplify
code: | if x (i) >= chr (97) and x (i) <= chr (122) or x (i) >= chr (65) and x (i) <= chr (90) then |
to
code: | if x (i) >= 'a' and x (i) <= 'z' or x (i) >= 'A' and x (i) <= 'Z' then |
oh, and why is it the 'Palindrome' program? |
|
|
|
|
![](images/spacer.gif) |
Clayton
![](http://compsci.ca/v3/uploads/user_avatars/1718239683472e5c8d7e617.jpg)
|
Posted: Thu Nov 30, 2006 4:22 pm Post subject: (No subject) |
|
|
actually, you can simplify that even further, because all characters are sequential in ASCII values, it can be:
code: |
if x(i) >= 'a' and x(i) <= 'Z' then
|
|
|
|
|
|
![](images/spacer.gif) |
|