Skip to main content

Mbstring

Latest Version: 1.0.0

This library implements a multibyte string class that can read, write and manipulate UTF-8 strings.

You can view the library’s source code on GitHub. Click here to see information on other versions of this library.

To add this library to your project, add #require "mbstring.class.nut:1.0.0" to the top of your agent and/or device code

Class Methods

The class supports the following string-like operations:

  • foreach() — Loops over each multibyte character (delivered as a series of strings).
  • len() — Returns the number of multibyte characters not the byte length.
  • slice() — Returns a sub-mbstring.
  • find() — Searches an mbstring for the first occurence of another string or mbstring.
  • tostring() — Converts the mbstring back to a UTF-8 string.
  • tointeger() — Converts the mbstring back to a UTF-8 string and then converts that into an integer.
  • tofloat() — Converts the mbstring back to a UTF-8 string and then converts that into a float.

Class Usage Example

#require "mbstring.class.nut:1.0.0"

local fr = mbstring("123«€àâäèéêëîïôœùûüÿçÀÂÄÈÉÊËÎÏÔŒÙÛÜŸ»")

foreach (x in fr.slice(1, 4)) {
    server.log("Char: " + x);
}

server.log("Find: " + fr.find("ëîïôœ"));

server.log("Euro: " + fr[4]);

Release History

The Electric Imp Dev Center documents the latest version of the library. For past versions, please see the Electric Imp public GitHub repos listed below.

Version Source Code Notes
1.0.0 GitHub Initial release

License

The mbstring class is licensed under MIT License.