Sample code for 30+ languages & platforms
Rust

Decode from Binary Encoding and Append String

Demonstrates how to decode from a binary encoding (base64, hex, url, etc.) and then append the decoded string to a Chilkat StringBuilder object.

Note: This example uses the new DecodeAndAppend method added in Chilkat v9.5.0.87.

Chilkat Rust Downloads

Rust

// We have the string "MÆRSK" in two forms:

// This is the URL encoding of the windows-1252 representation.
let name_windows1252_url_encoded = "M%C6RSK".to_string();

// This is the URL encoding of the utf-8 representation.
let name_utf8_url_encoded = "M%C3%86RSK".to_string();

// Note that the result of loading a string into a string object 
// is the same if we correctly specify the underlying charset encoding.
// In the above example, we have the same string, but in different charset encodings
// subsequently URL encoded.
let sb1 = chilkat::StringBuilder::new();
let _ = sb1.decode_and_append(&name_windows1252_url_encoded, "url", "windows-1252").is_ok();

let sb2 = chilkat::StringBuilder::new();
let _ = sb2.decode_and_append(&name_utf8_url_encoded, "url", "utf-8").is_ok();

// sb1 and sb2 both hold the same string.
let b_equal = sb1.contents_equal_sb(&sb2, true);
println!("bEqual = {}", b_equal);

// We can see the string is "MÆRSK" in both cases.
println!("{}", sb1.get_as_string().unwrap_or_default());
println!("{}", sb2.get_as_string().unwrap_or_default());