Titanium.Codec.encodeString

Function of Titanium.Codec.
Platform Since
Android 1.7
iPhone 1.7
iPad 1.7

Summary

Encodes the String source into dest using charset. Throws an Exception if charset is not a valid character set, source is null, or either sourcePosition, sourceLength, or sourcePosition+sourceLength is greater than source.length.

Code Examples

Encode and trim a simple String using the UTF-8 (default) charset

var buffer = Ti.createBuffer({ length: 1024 });
var length = Ti.Codec.encodeString({
    source: "hello world",
    dest: buffer
});
buffer.length = length;

Encode the first 10 characters of a String using the UTF-16 charset

// (10 * 2) + BOM = 22
var buffer = Ti.createBuffer({ length: 22 });
Ti.Codec.encodeString({
    source: "jack jumped over the candle stick",
    sourceLength: 10,
    dest: buffer,
    charset: Ti.Codec.CHARSET_UTF16
});

Arguments

Name Type Summary
options Dictionary<EncodeStringDict>

encodeString named options

Return Type

Number