Author |
Message |
Flikerator
|
Posted: Wed Mar 09, 2005 3:13 pm Post subject: Intstr/strint and other |
|
|
Alright I competed today and if I know how to intstr and strint then We would have come ontop. Instead we had to do a lot of other stuff and it wasted time...
So I need a good explaination of how to turn a string into an int and vice versa. Example of what we had;
You get a string from some data on a disk. It has to then be turned into an integer for our math calculation. We got it right but it took a lot longer.
code: | var word : string := "123772183"
for i : 1 .. length (word)
word (i .. i) %needs this to be turned into an int
end for |
Thats a bad example because it was only one number we needed and here its asking for each letter at a time. I just need to know how to take a string and make it into an integer value. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Bacchus
|
Posted: Wed Mar 09, 2005 3:28 pm Post subject: (No subject) |
|
|
code: | var word : string := "123772183"
var num:int
if strintok(word) then
num:=string(word)
end if |
|
|
|
|
|
|
Flikerator
|
Posted: Wed Mar 09, 2005 3:54 pm Post subject: (No subject) |
|
|
Quote: var word : string := "123772183"
var num:int
if strintok(word) then
num:=string(word)
end if
ERROR
Compile time expression expected
You didnt explain what you did, that doesnt help >< |
|
|
|
|
|
person
|
Posted: Wed Mar 09, 2005 4:04 pm Post subject: (No subject) |
|
|
code: |
var word : string := "123772183"
for i : 1 .. length (word)
strint (word (i)) %needs this to be turned into an int
end for
|
btw : not sure wat "i..i" means |
|
|
|
|
|
Flikerator
|
Posted: Wed Mar 09, 2005 4:07 pm Post subject: (No subject) |
|
|
person wrote: code: |
var word : string := "123772183"
for i : 1 .. length (word)
strint (word (i)) %needs this to be turned into an int
end for
|
btw : not sure wat "i..i" means
Well if i is 1 then,
letter in place 1-1 will be shown. If its 3 then letter 3-3 will be shown. |
|
|
|
|
|
person
|
Posted: Wed Mar 09, 2005 4:11 pm Post subject: (No subject) |
|
|
so was wat i gave u helpful???
btw: still doesnt understand the i..i thing |
|
|
|
|
|
Flikerator
|
Posted: Wed Mar 09, 2005 4:22 pm Post subject: (No subject) |
|
|
Quote: var word : string := "1237721830"
put word %Shows you the word
put "" %Adds a space
for i : 1 .. length (word)
put word (i .. i) .. %Lets the next put go beside it
put word (i) %Another way to do it
end for
put ""
break
for i : 1 .. length (word) - 1 by 2 %Goes up 2
put word (i .. i + 1) %Puts the current number to the current number+1
end for
No it didn't help.
Ill make it a bit simpler, I can do the difficult stuff after I learn it.
If I had;
Quote: var word : string := "5"
How do I make that an int? |
|
|
|
|
|
person
|
Posted: Wed Mar 09, 2005 4:27 pm Post subject: (No subject) |
|
|
code: |
var something:int
something:=strint (word)
|
or if ur not sure if word can be turned to int u can do
code: |
var something :int
if strintok (word) then
something:=strint (word)
end if
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Bacchus
|
Posted: Wed Mar 09, 2005 4:32 pm Post subject: (No subject) |
|
|
srry it was a typo, i put string instead of strint
code: | var word : string := "123772183" %declaring the string that will become and int
var num:int %variable to take int
if strintok(word) then %if the string is ok to turn into int (all integers)
num:=strint(word) %string->integer and stored into var
end if
put word %put each word to compare, both the same
put num %but one is accually in int variable |
|
|
|
|
|
|
Flikerator
|
Posted: Wed Mar 09, 2005 4:41 pm Post subject: (No subject) |
|
|
Bacchus wrote: srry it was a typo, i put string instead of strint
code: | var word : string := "123772183" %declaring the string that will become and int
var num:int %variable to take int
if strintok(word) then %if the string is ok to turn into int (all integers)
num:=strint(word) %string->integer and stored into var
end if
put word %put each word to compare, both the same
put num %but one is accually in int variable |
Alright thanks. I wish I asked this yesterday, but oh well. Thanks again ^^; |
|
|
|
|
|
person
|
Posted: Wed Mar 09, 2005 6:03 pm Post subject: (No subject) |
|
|
... ... ... ... ... ...but...but...but mine did the same thing (almost)...*tear* |
|
|
|
|
|
Flikerator
|
Posted: Wed Mar 09, 2005 6:05 pm Post subject: (No subject) |
|
|
person wrote: ... ... ... ... ... ...but...but...but mine did the same thing (almost)...*tear*
Thank you ^^
I just read the last post and didn't see yours sry ^^; |
|
|
|
|
|
|