Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 String Limit
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
mike200015




PostPosted: Mon Feb 21, 2005 3:02 pm   Post subject: String Limit

is there a way to limit the amount of letters that will be output? I know you can do: var x :string (6) which will only allow an input of at most 6 letters, but then when more than 6 letters are input then it screws up the game by exitting and going to the code. Is there a way to allow as many letters to be input, but then it will only output the 1st 6 letters?
Sponsor
Sponsor
Sponsor
sponsor
Flikerator




PostPosted: Mon Feb 21, 2005 3:20 pm   Post subject: (No subject)

code:
var word : string
get word
if length (word) =< 6 then
    word := word
else
    word := ""
end if


Or if you want to keep asking for the word till you get it;

code:
var word : string

loop
    get word
    exit when length (word) <= 6
end loop
mike200015




PostPosted: Mon Feb 21, 2005 3:26 pm   Post subject: (No subject)

thnx.. can u help me wit a couple other things flikerator?
mike200015




PostPosted: Mon Feb 21, 2005 3:32 pm   Post subject: (No subject)

[quote="Flikerator"]
code:
var word : string
get word
if length (word) =< 6 then
    word := word
else
    word := ""
end if


that doesnt work tho, if the name is longer than 6 it just shows up blank, i want it to; if the name is longer than 6 ,to only show the first 6 letters.
Andy




PostPosted: Mon Feb 21, 2005 3:36 pm   Post subject: (No subject)

err y not just go put word(1..6)
cycro1234




PostPosted: Mon Feb 21, 2005 3:39 pm   Post subject: (No subject)

var word : string
get word
if length (word) <= 6 then
word := word
else
word := word(1..6)
end if
mike200015




PostPosted: Mon Feb 21, 2005 3:48 pm   Post subject: (No subject)

code:

var word : string
get word
if length (word) <= 6 then
word := word
else
word := word(1..6)
end if


just tired it, and it didnt work Confused
AsianSensation




PostPosted: Mon Feb 21, 2005 4:26 pm   Post subject: (No subject)

why not? It works fine for me.

Maybe because you were too lazy to include:

code:
put word
after the end if?
Sponsor
Sponsor
Sponsor
sponsor
Flikerator




PostPosted: Mon Feb 21, 2005 4:32 pm   Post subject: (No subject)

Andy wrote:
err y not just go put word(1..6)


That would just display the first six letters not make it have six letters. If thats what he wants then that will work but;

If I enter Flikerator (10 letters) and then put;

put name(1..6) then my name is still flikerator but it just displays six letters.

Quote:
thnx.. can u help me wit a couple other things flikerator?


What other things?
Tony




PostPosted: Mon Feb 21, 2005 5:33 pm   Post subject: (No subject)

Flikerator wrote:
Andy wrote:
err y not just go put word(1..6)

That would just display the first six letters

Turing:

name := word(1..6)

no? Thinking
McKenzie




PostPosted: Mon Feb 21, 2005 6:06 pm   Post subject: (No subject)

That crashes if length < 6. Try
code:
put name(1..min(6,length(name)))
mike200015




PostPosted: Mon Feb 21, 2005 6:18 pm   Post subject: (No subject)

jus tried your way McKenzie, it didnt work cuz im using Font.Draw so when i put your code in, then it only showed like the 1st letter right at the right side of the screen, and the rest of it was off the screen Confused Sad
Flikerator




PostPosted: Mon Feb 21, 2005 6:18 pm   Post subject: (No subject)

tony wrote:
Flikerator wrote:
Andy wrote:
err y not just go put word(1..6)

That would just display the first six letters

Turing:

name := word(1..6)

no? Thinking


Yes but lets say he is making a character generater. Now for the rest of the game my name is now "Fliker" because I didn't know. I even ignored the warning he supplied when he told me to choose my name Razz

Quote:
put name (1 .. min (6, length (name)))

Again my name will show Fliker but will still be Flikerator.
mike200015




PostPosted: Mon Feb 21, 2005 6:25 pm   Post subject: (No subject)

what i want to do is; since im using Font.Draw, the x-coordinate of the Font.Drawargument to be sumthing like maxx-length(name)-3, so that the name they enter will be fully shown and the last letter about 3 spaces away from maxx. Except that way doesnt work. Does anyone know how to do it like that using Font.Draw?
Cervantes




PostPosted: Mon Feb 21, 2005 7:26 pm   Post subject: (No subject)

Use Font.Width.
And don't ask what Font.Width does. Use the help file. And don't ask how you should use Font.Width, because it's simple. Think about things before you ask. (Sorry, it's just this whole thread seems to be people giving you perfectly good code and you saying "no it doesn't work".)
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 18 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: