Print only a part from a string [solved]

Monkey Forums/Monkey Programming/Print only a part from a string [solved]

Raul(Posted 2014) [#1]
I want to make a simple effect to draw a text character by character with a pause between them.

I am loading my text into a string. How to print only the first X characters of the string?


dawlane(Posted 2014) [#2]
Read the about the String type in the documentation. http://www.monkey-x.com/docs/html/Programming_Language%20reference.html#types
The answer is in there.


ziggy(Posted 2014) [#3]
You can just create a substring
Function Main()
    Local myString:="Hello world!"
    Print myString[..1]
    Print myString[..2]
    Print myString[..3]
    Print myString[..4]
End

This outputs:
H
He
Hel
Hell


Raul(Posted 2014) [#4]
thank you dawlane. I found what I needed there.

Edit:
@ziggy: you posted while I was replying and that code gave me the perfect idea :D

thanks


ziggy(Posted 2014) [#5]
Notice you can use negative indexes to get latest chars insted of first chars. I found that very useful


dawlane(Posted 2014) [#6]
I would have thought that a negative index would have thrown an index out of range error.


Raul(Posted 2014) [#7]
@ziggy: wow. that a nice effect.


ziggy(Posted 2014) [#8]
It's a documented implementation detail, not a side effect or anything like this, and sometimes it's quite handy!