Example:
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``
stdout.puts (str3 + "\n");
// Copy:
// Output: ``0x82e4588 != 0x82e45a8true``
string str4 = str3;
stdout.printf ("%p != %p\n", str3, str4);
// Compare:
// Output: ``true``
if (str4 == str3) {
stdout.puts ("true\n");
} else {
stdout.puts ("false\n");
}
// Verbatim strings:
// Output:
// ``\tfoo``
// ``bar``
// ``\t``
string str5 = """\tfoo
bar
\t
""";
stdout.puts (str5);
return 0;
}
valac --pkg glib-2.0 string.vala
- public unowned string? str (string needle)
- public unowned string? rstr (string needle)
- public unowned string? rstr_len (ssize_t haystack_len, string needle)
Searches the string haystack for the last occurrence of the
string needle, limiting the length of the search to haystack_len.
- public int index_of (string needle, int start_index = 0)
Finds the leftmost occurrence of the given string.
- public int last_index_of (string needle, int start_index = 0)
Find the rightmost 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 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 bool has_prefix (string prefix)
Looks whether the string str begins with prefix.
- public bool has_suffix (string suffix)
Looks whether the string str ends with suffix.
- public string printf (...)
- 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.
- public int scanf (...)
Reads the data from string
- public string concat (string string2, ...)
Concatenates all of the given strings into one long string.
- public string escape (string exceptions)
Escapes the special characters '\b', '\f', '\n', '\r', '\t', '\v', '\' and
'"' in the string source by inserting a '\' before them.
- public string compress ()
Replaces all escaped characters with their one byte equivalent.
- public string[] split (string delimiter, int max_tokens = 0)
Splits a string into a maximum of max_tokens pieces, using
the given delimiter.
- public string[] split_set (string delimiters, int max_tokens = 0)
Splits string into a number of tokens not containing any of
the characters in delimiter.
- public char @get (long index)
Returns the byte at the given index
- public bool valid_char (int index)
Checks whether valid string character starts at specified index.
- public unowned string next_char ()
- public bool get_next_char (ref int index, out unichar c)
Finds the next UTF-8 character in the string after index.
- 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 unowned string utf8_offset (long offset)
- public unowned string offset (long offset)
- public long pointer_to_offset (string pos)
- public int index_of_nth_char (long c)
Converst utf8-char-position to a byte offset.
- public unowned string prev_char ()
- public bool get_prev_char (ref int index, out unichar c)
Finds the previous UTF-8 character in the string before index
.
- public long len ()
- public unowned string chr (ssize_t len, unichar c)
- public unowned string rchr (ssize_t len, unichar c)
- public string reverse (ssize_t len = -1)
Reverses a UTF-8 string.
- public bool validate (ssize_t max_len = -1, out char* end = null)
Validates UTF-8 encoded text.
- 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 string up (ssize_t len = -1)
Converts all Unicode characters in the string that have a case to
uppercase.
- public string down (ssize_t len = -1)
Converts all Unicode characters in the string that have a case to
lowercase.
- public string casefold (ssize_t len = -1)
Converts a string into a form that is independent of case.
- 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 locale_to_utf8 (ssize_t len, out size_t bytes_read, out size_t bytes_written, out Error error = null)
- public unowned string _chomp ()
Removes trailing whitespace from a string.
- public 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 string chug ()
Removes leading whitespace from a string.
- public unowned string _strip ()
- public string strip ()
Removes leading and trailing whitespace from a string.
- public unowned string _delimit (string delimiters, char new_delimiter)
Converts any delimiter characters in string to
new_delimiter.
- public string delimit (string delimiters, char new_delimiter)
Converts any delimiter characters in string to
new_delimiter.
- public uint hash ()
- public int to_int ()
- public long to_long (out string endptr = null, int _base = 0)
- public double to_double (out string endptr = null)
- public ulong to_ulong (out string endptr = null, int _base = 0)
- public int64 to_int64 (out string endptr = null, int _base = 0)
- public uint64 to_uint64 (out string endptr = null, int _base = 0)
- public bool to_bool ()
- public size_t size ()
- public int ascii_casecmp (string s2)
Compare two strings, ignoring the case of ASCII characters.
- public int ascii_ncasecmp (string s2, size_t n)
Compare s1 and s2, ignoring the case of ASCII
characters and any characters after the first n in each string.
- public void canon (string valid_chars, char substitutor)
For each character in string, if the character is not in
valid_chars, replaces the character with substitutor.
- public string dup ()
- public string ndup (size_t n)
- 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 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 bool contains (string needle)
Checks if a needle exists in string
- public string replace (string old, string replacement)
Replace all occurrences of the search string with the replacement string
- public int char_count (ssize_t max = -1)
Computes the length of the string in characters, not including the
terminating nul character.
- public char[] to_utf8 ()
Returns the string as a UTF-8 char array
- public unowned string to_string ()
Converts the value to its equivalent string representation