get_string


Description:

public unowned string get_string (out size_t length = null)

Returns the string value of a Variant instance with a string type.

This includes the types g_variant_type_string, g_variant_type_object_path and g_variant_type_signature.

The string will always be UTF-8 encoded, and will never be null.

If length is non-null then the length of the string (in bytes) is returned there. For trusted values, this information is already known. For untrusted values, a size will be performed.

It is an error to call this function with a this of any type other than those three.

The return value remains valid as long as this exists.

Example: Get a string:

public static int main (string[] args) {
Variant var1 = new Variant.string ("Hello, world!");
size_t length = 0;

// Output: ``'Hello, world!', 13``
print ("'%s', %"+size_t.FORMAT+"\n", var1.get_string (out length), length);

return 0;
}

valac --pkg glib-2.0 GLib.Variant.get_string.vala

Parameters:

this

a string Variant instance

length

a pointer to a size_t, to store the length

Returns:

the constant string, UTF-8 encoded