Handling strings in moonbit

I see the compiler understands the type Char (still undocumented), how do you envision it being used?
For example, how would you create a string constructor that can take a Char as input?

Hello @luciodj , we are still working on utilities for the Char, String, and other builtin types. Here’s what you can do with them for now:

fn init {
  let c = 'c'
  let str1 = c.to_string()
  let str2 = String::make(3, 'c')
}

Nice thanks for sharing!
I must confess, I had this crazy idea of trying to learn/put Moonbit through its paces for the Advent of Code 2023 annual coding marathon…
I guess it is a little too soon though, even attempting to write some of the usual libs myself would be too hard now. Maybe the 2024 Advent of Code then… :smiley:

Hey there, we’re thrilled to hear about your enthusiasm for Moonbit! It’s always exciting to see our users eager to dive in and put the language to the test.

We’re currently in the thick of developing our package infrastructure and are aiming to provide a seamless experience akin to what you’d find with crates.io and docs.rs. This should make the process of writing and sharing libraries much smoother.

While it might be a bit premature for this year’s Advent of Code, we are definitely targeting improvements that will support such endeavors for Advent of Code 2024. So hang in there! We’re working hard to make sure Moonbit has all the tools and libraries you’ll need to tackle coding challenges with confidence.

Stay tuned for updates and, as always, we’re grateful for your support and patience as we build out these capabilities. Happy coding, and we can’t wait to see what you’ll create with Moonbit in the future! :blush:

1 Like

How to get a substring of a string?

We are still working on the standard library. There’s no method on string to take the substring. The current workaround is to use bytes, for example:

fn init {
  let s = "hello"
  let b = s.to_bytes()
  let s1 = b.sub_string(1, 3)
  print(s1)
}
1 Like