Author |
Message |
KC 40oz
|
Posted: Tue Nov 15, 2005 10:03 am Post subject: Need help identifying a function |
|
|
I'm making a binary -> decimal convertor and i need the function that counts the # of digits in a variable and also that can grab single digits
i am SURE i learned this last year, but the help file at my school isnt working right now
any help would be appreciated |
|
|
|
|
|
Sponsor Sponsor
|
|
|
ZeroPaladn
|
Posted: Tue Nov 15, 2005 10:20 am Post subject: (No subject) |
|
|
lolz, i did this for extra credit this september, although i didnt know that there was a function for it . What i did is that i used the number 256 (1 as the 9th digit of binary) and kept deviding it by 2, then checking to see if i could minus certain numbers from it. heres the post for it, and there are tons of other submissions for it too. study it.
http://www.compsci.ca/v2/viewtopic.php?t=9806 |
|
|
|
|
|
Albrecd
|
Posted: Tue Nov 15, 2005 10:40 am Post subject: length |
|
|
Use "length (variable)"
Ex:
code: | var a :string
put "Write something"
get a:*
put "The length of your writing masterpiece is ",length (a)," characters." |
|
|
|
|
|
|
do_pete
|
Posted: Tue Nov 15, 2005 11:27 am Post subject: (No subject) |
|
|
length(variable) is for strings. So in order to use that you would have to convert the interger into a string using intstr() |
|
|
|
|
|
KC 40oz
|
Posted: Tue Nov 15, 2005 12:37 pm Post subject: (No subject) |
|
|
ok thanks, i also need to be able to extract a certain char from the string, and i remember doing that yet cant remember for the life of me what the function was
i remember it including * s to signify the last char in the string |
|
|
|
|
|
do_pete
|
Posted: Tue Nov 15, 2005 12:49 pm Post subject: (No subject) |
|
|
i don't know about the *s but you just go something like this
code: | Character:=String(number) |
Character is the character you want to isolate. String is the string and number is the number of the character. for example this would print "r" becuase "r" is the third character in the string "turing"
code: | var text:string:="turing"
put text(3) |
|
|
|
|
|
|
codemage
|
Posted: Tue Nov 15, 2005 1:09 pm Post subject: (No subject) |
|
|
Treat strings like you would arrays of characters.
var x : string := "abcdefghijklmn"
put x (3)
-> puts out "c"
put x (5..*-2)
- >puts out "efghijkl"
You can use index and length for more in-depth string manipulation. |
|
|
|
|
|
|