string – glib-2.0 (original) (raw)
Object Hierarchy:
string string string
Description:
[ Compact ]
[ Immutable ]
[ GIR ( name = "utf8" ) ]
[ CCode ( cname = "gchar" , const_cname = "const gchar" , copy_function = "g_strdup" , free_function = "g_free" , get_value_function = "g_value_get_string" , marshaller_type_name = "STRING" , param_spec_function = "g_param_spec_string" , set_value_function = "g_value_set_string" , take_value_function = "g_value_take_string" , type_id = "G_TYPE_STRING" , type_signature = "s" ) ]
public class string
Example: General samples:
public static int main (string[] args) {
string str1 = "U = R * I";
string str2 = "R = U / I";
string str3 = @"$str1; $str2";
// Concat:
// Output: ``U = R * I; R = U / I``
print (str3 + "\n");
// Copy:
// Output: ``0x82e4588 != 0x82e45a8true``
string str4 = str3;
print ("%p != %p\n", str3, str4);
// Compare:
// Output: ``true``
if (str4 == str3) {
print ("true\n");
} else {
print ("false\n");
}
// Verbatim strings:
// Output:
// ``\tfoo``
// ``bar``
// ``\t``
string str5 = """\tfoo
bar
\t
""";
print (str5);
return 0;
}
valac --pkg glib-2.0 string.vala
Content:
Properties:
- public uint8[] data { get; }
The string as a sequence of bytes - public int length { get; }
Returns the length of the given string in bytes.
Static methods:
- public static string join (string separator, ...)
Joins a number of strings together to form one long string, with the optionalseparator
inserted between each of them. - public static string joinv (string? separator, string?[]? str_array)
- public static string nfill (size_t length, char fill_char)
Creates a new stringlength
bytes long filled withfill_char
. - public static bool set_str (ref string str, string new_str)
Methods:
- public char @get (long index)
Returns the byte at the given index - public unowned string _chomp ()
Removes trailing whitespace from a string. - public unowned string _chug ()
Removes leading whitespace from a string, by moving the rest of the characters forward. - public unowned string _delimit (string delimiters, char new_delimiter)
Converts any delimiter characters instring
tonew_delimiter
. - public unowned string _strip ()
- public int ascii_casecmp (string s2)
Compare two strings, ignoring the case of ASCII characters. - public string ascii_down (ssize_t len = -1)
Converts all upper case ASCII letters to lower case ASCII letters, with semantics that exactly match [func@GLib. - public int ascii_ncasecmp (string s2, size_t n)
Compares1
ands2
, ignoring the case of ASCII characters and any characters after the firstn
in each string. - public string ascii_up (ssize_t len = -1)
Converts all lower case ASCII letters to upper case ASCII letters, with semantics that exactly match [func@GLib. - public void canon (string valid_chars, char substitutor)
For each character instring
, if the character is not invalid_chars
, replaces the character withsubstitutor
. - public string casefold (ssize_t len = -1)
Converts a string into a form that is independent of case. - public int char_count (ssize_t max = -1)
Computes the length of the string in characters, not including the terminating nul character. - public string chomp ()
Removes trailing whitespace from a string. - public unowned string chr (ssize_t len, unichar c)
- public string chug ()
Removes leading whitespace from a string. - public int collate (string str2)
Compares two strings for ordering using the linguistically correct rules for the current locale. - public string collate_key (ssize_t len = -1)
Converts a string into a collation key that can be compared with other collation keys produced by the same function using strcmp. - public string collate_key_for_filename (ssize_t len = -1)
Converts a string into a collation key that can be compared with other collation keys produced by the same function using strcmp. - public string compress ()
Replaces all escaped characters with their one byte equivalent. - public string concat (string string2, ...)
Concatenates all of the given strings into one long string. - public bool contains (string needle)
Checks if aneedle
exists in string - public string delimit (string delimiters, char new_delimiter)
Converts anydelimiter
characters in string tonew_delimiter
. - public string down (ssize_t len = -1)
Converts all Unicode characters in the string that have a case to lowercase. - public string dup ()
- public string escape (string? exceptions = null)
Escapes the special characters '\b', '\f', '\n', '\r', '\t', '\v', '\' and '"' in the stringsource
by inserting a '\' before them. - public unichar get_char (long index = 0)
Converts a sequence of bytes encoded as UTF-8 to a Unicode character. - public unichar get_char_validated (ssize_t max_len = -1)
Convert a sequence of bytes encoded as UTF-8 to a Unicode character. - public bool get_next_char (ref int index, out unichar c)
Finds the next UTF-8 character in the string afterindex
. - public bool get_prev_char (ref int index, out unichar c)
Finds the previous UTF-8 character in the string beforeindex
. - public bool has_prefix (string prefix)
Looks whether the stringstr
begins withprefix
. - public bool has_suffix (string suffix)
Looks whether a string ends withsuffix
. - public uint hash ()
- public int index_of (string needle, int start_index = 0)
Finds the leftmost occurrence of the given string. - public int index_of_char (unichar c, int start_index = 0)
Finds the leftmost occurrence of the given Unicode character in a UTF-8 encoded string. - public int index_of_nth_char (long c)
Converst utf8-char-position to a byte offset. - public bool is_ascii ()
Determines if a string is pure ASCII. - public int last_index_of (string needle, int start_index = 0)
Find the rightmost occurrence of the given string. - public int last_index_of_char (unichar c, int start_index = 0)
Find the rightmost occurrence of the given Unicode character in a UTF-8 encoded string. - public long len ()
- public string locale_to_utf8 (ssize_t len, out size_t bytes_read, out size_t bytes_written, out Error error = null)
Converts a string which is in the encoding used for strings by the C runtime (usually the same as that used by the operating system) in the current locale into a UTF-8 string. - public string make_valid (ssize_t len = -1)
If the provided string is valid UTF-8, return a copy of it. - public bool match_string (string search_term, bool accept_alternates)
Checks if a search conducted forsearch_term
should matchpotential_hit
. - public string ndup (size_t n)
- public unowned string next_char ()
- public string normalize (ssize_t len = -1, NormalizeMode mode = DEFAULT)
Converts a string into canonical form, standardizing such issues as whether a character with an accent is represented as a base character and combining accent or as a single precomposed character. - public unowned string offset (long offset)
- public long pointer_to_offset (string pos)
- public unowned string prev_char ()
- public string printf (...)
- public unowned string rchr (ssize_t len, unichar c)
- public string replace (string old, string replacement, int max_tokens = -1)
Replace occurrences of the search string with the replacement string at a maximum of max_tokens - public string reverse (ssize_t len = -1)
Reverses a UTF-8 string. - public unowned string? rstr (string needle)
- public unowned string? rstr_len (ssize_t haystack_len, string needle)
Searches the stringhaystack
for the last occurrence of the stringneedle
, limiting the length of the search tohaystack_len
. - public int scanf (string format, ...)
Reads the data from string - public size_t size ()
- public string slice (long start, long end)
Extracts the text from one string and returns a new string. - public string splice (long start, long end, string? str = null)
Removes a portion of the string and replaces it with something else. - public string[] split (string delimiter, int max_tokens = 0)
Splits a string into a maximum ofmax_tokens
pieces, using the givendelimiter
. - public string[] split_set (string delimiters, int max_tokens = 0)
Splitsstring
into a number of tokens not containing any of the characters indelimiters
. - public unowned string? str (string needle)
- public string strip ()
Removes leading and trailing whitespace from a string. - public string substring (long offset, long len = -1)
Returns the characters in a string beginning at the specified location through the specified number of characters. - public string to_ascii (string? from_locale = null)
Transliteratestr
to plain ASCII. - public bool to_bool ()
- public double to_double (out unowned string endptr = null)
- public int to_int ()
- public int64 to_int64 (out unowned string endptr = null, int _base = 0)
- public long to_long (out unowned string endptr = null, int _base = 0)
- public unowned string to_string ()
Converts the value to its equivalent string representation - public uint64 to_uint64 (out unowned string endptr = null, int _base = 0)
- public ulong to_ulong (out unowned string endptr = null, int _base = 0)
- public string16 to_utf16 (long len = -1, out long items_read = null, out long items_written = null) throws ConvertError
Convert a string from UTF-8 to UTF-16. - public string32 to_utf32 (long len = -1, out long items_read = null, out long items_written = null) throws ConvertError
Convert a string from UTF-8 to a 32-bit fixed width representation as UCS-4. - public string32 to_utf32_fast (long len = -1, out long items_written = null)
Convert a string from UTF-8 to a 32-bit fixed width representation as UCS-4, assuming valid UTF-8 input. - public char[] to_utf8 ()
Returns the string as a UTF-8 char array - public string[] tokenize_and_fold (string transit_locale, out string[] ascii_alternates)
Tokenizesstring
and performs folding on each token. - public string truncate_middle (size_t truncate_length)
Cuts off the middle of the string, preserving half oftruncate_length
characters at the beginning and half at the end. - public string up (ssize_t len = -1)
Converts all Unicode characters in the string that have a case to uppercase. - public unowned string utf8_offset (long offset)
- public bool valid_char (int index)
Checks whether valid string character starts at specified index. - public bool validate (ssize_t max_len = -1, out char* end = null)
Validates UTF-8 encoded text. - public bool validate_len (size_t max_len, out char* end = null)
Validates UTF-8 encoded text. - public string vprintf (va_list args)
Similar to the standard C `vsprintf()` function but safer, since it calculates the maximum space required and allocates memory to hold the result.