Can we subscript a String in mojo? #95
-
In Python strings, you can do this: s = 'hello, world'
print(s[0]) In mojo, this doesn't work: let s = 'hello, world'
print(s[0])
Similar errors for doing this with String or StringRef objects too. Are there other alternatives available at the moment to achieve the equivalent? Or someway to convert the String into an array/vector of underlying bytes? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
That should work. Probably just not implemented yet. If you use the Python.str type for now, I would think you could work around that.
|
Beta Was this translation helpful? Give feedback.
-
Try this from String import String
print(String("hello")[2]) |
Beta Was this translation helpful? Give feedback.
Thanks, I had tried this last week. Looks like in the latest release they added support for this.