Getting slices from strings, how to make it work?

BlitzMax Forums/BlitzMax Beginners Area/Getting slices from strings, how to make it work?

Smurftra(Posted 2006) [#1]
Local sSource:String
Local sTest:String
sSource = "This is a test"

sTest = sSource[1]

Print sTest
Print sSource[1]

given that source code

if i run it, it prints

104
104

and not

h
h

which is what i was expecting

why is that? And how do i fix it without using Mid (i want to use slices)

How come

Print sSource[1..] prints

his is a test

but

Print sSource[1..1] prints nothing?

I'm confused.


Note: I've search the site and the examples/posts i found described this as working:

http://www.blitzmax.com/Community/posts.php?topic=59682#665364


Perturbatio(Posted 2006) [#2]
print sSource[..1]?


Smurftra(Posted 2006) [#3]
.. what if i want the 5th character

i dont want to print it either, its just for debut purposes

I want it to be assigned to sTest

so if i print sTest, it will show the correct string


N(Posted 2006) [#4]
sSource[5..6]

Or it might be [4..5], I can't be bothered to check at the moment. You can probably figure it out from there.

As for getting a number from s[i], s[i] returns the unicode character, not a string.


Perturbatio(Posted 2006) [#5]
Print sSource[4..5]


tonyg(Posted 2006) [#6]
. (too slow)


Smurftra(Posted 2006) [#7]
So basicaly, slicing ( [a..b] ) works from a to b-1?


tonyg(Posted 2006) [#8]
... from a for length (b-a)...
The length of the returned slice is always EndIndex - StartIndex elements long,
.. Blitzmax help files.


Smurftra(Posted 2006) [#9]
thanks alot