Sidef::Types::String::String
This class implements ...
var obj = String(...)
Inherits methods from:
* Sidef::Object::Object
format_str % (args...)
Returns a string that is formatted according to a specified format string and arguments.
Parameters:
format_str : A string that specifies the format of the output string. It can contain placeholders that are replaced by the values of the arguments passed to the function. args... : Any number of arguments that are used to replace the placeholders in the format string. The number of arguments must match the number of placeholders in the format string.
Aliases: sprintf
str1 & str2
Performs a bitwise AND operation on two strings and returns the result as a new string.
Aliases: and
str * n
Takes a string str and a non-negative integer n as input and returns a new string consisting of n copies of str concatenated together.
str
n
Aliases: mul, repeat
str1 + str2
Concatenates two strings into a single string.
Aliases: add, append, concat
a++
Increments an alphanumeric string to the next ASCIIbetical string.
Aliases: inc
str - substr str - regex
Remove from str the first occurrence of substr:
substr
'fo boo' - 'o' #=> 'fo boo'
When a regular expression is given, it removes all occurrences matched by the regex:
'foo boo' - /o/ #=> 'f b'
Aliases: diff
a .. b
Returns a RangeStr object: RangeStr(a, b).
RangeStr(a, b)
Aliases: to, upto
str / n
Divide the str into at least n parts, returing an Array object.
'foobar' / 2 => ["foo", "bar"] 'fooba' / 2 => ["fo", "ob", "a"]
Aliases: ÷, div
str1 < str2
Returns true if str1 is lexicographically less than str2.
str1
str2
Aliases: lt
str << n
Returns a new string that is formed by dropping the first n characters from the input string.
Aliases: drop_left, shift_left
str1 <=> str2
Compares two strings lexicographically and returns an integer that represents their relative order.
If str1 is lexicographically less than str2, the function returns a negative integer.
If str1 is lexicographically greater than str2, the function returns a positive integer.
If the two strings are equal, the function returns 0.
0
Aliases: cmp
str1 == str2
Compares if the given two strings are equal to each other. If the two strings are equal, the function returns true.
Aliases: eq
str =~ regex str.match(regex, pos)
Searches for a match between a regular expression and a string, starting from a specified position in the string. It returns a match object.
regex : A regular expression to be matched against the string. pos : An integer that represents the position in the string where the search is to begin. The default value is 0, which means the search starts from the beginning of the string.
Aliases: match
str1 > str2
Returns true if str1 is lexicographically greater than str2.
Aliases: gt
str >> n
Returns a new string that is formed by dropping the last n characters from the input string.
Aliases: drop_right, shift_right
str1 ^ str2
Performs a bitwise XOR operation on two strings and returns the result as a new string.
Aliases: xor
str1 | str2
Performs a bitwise OR operation on two strings and returns the result as a new string.
Aliases: or
~str
Performs a bitwise unary NOT operation on the given string and returns the result as a new string.
Aliases: not
str1 ≠ str2
Compares if the given two strings are equal to each other. If the two strings are equal, the function returns false.
Aliases: !=, ne
str1 ≤ str2
Returns true if str1 is lexicographically less than or equal to str2.
Aliases: <=, le
str1 ≥ str2
Returns true if str1 is lexicographically greater than or equal to str2.
Aliases: >=, ge
self.apply_escapes(parser)
Returns the
str.ascii2bin
Takes a string of ASCII characters as input and returns a string of binary digits representing the ASCII values of the characters.
self.ascii2bits
Takes a string of ASCII characters as input and returns a string of bits representing the ASCII values of the characters. Each character is converted to its 8-bit binary representation.
self.backtick
str.base64_decode
Decodes a base64 encoded string into its original form.
Base64 is a binary-to-text encoding scheme that represents binary data in an ASCII string format by translating it into a radix-64 representation. The encoded string can be safely transferred or stored without any data loss or corruption. The base64_decode() method reverses the encoding process and converts the base64 string back to its original binary form.
base64_decode()
Aliases: decode_base64
str.base64_encode
Encodes a string in base64 format. Base64 is a binary-to-text encoding scheme that represents binary data in an ASCII string format by translating it into a radix-64 representation. The encoded string can be safely transferred or stored without any data loss or corruption. The base64_encode() method encodes the input string in base64 format.
base64_encode()
Aliases: encode_base64
str.begins_with(prefix)
Check whether a string starts with a given prefix string or not. It takes a string as an input and checks whether the string starts with the prefix string specified as an argument. If the string starts with the specified prefix, it returns True, otherwise, it returns False.
Aliases: starts_with
self.bin
str.bin2ascii
Converts a binary string into its equivalent ASCII string representation. It takes a binary string as an input and returns the equivalent ASCII string representation of the binary string.
str.bytes
Convert a string into an Array of bytes, ranging from 0 to 255.
255
str.bytes_len
Determine the length of a string in bytes. It takes a string as an input and returns the length of the string in bytes.
Aliases: bytes_length
self.center(size, char)
self.char(pos)
Aliases: char_at
str.chars
Convert a string into an Array of characters.
say "foo".chars #=> ["f", "o", "o"]
self.chomp
self.chop
self.clear
str.codes
Convert a string into an Array of code points.
say "foo".codes #=> [102, 111, 111] say "€".codes #=> [8364]
Aliases: code_points
self.collect(regex)
Aliases: find_all, findall
self.count(arg)
self.crypt(salt)
str.decode(enconding)
Decodes a string using a specified character encoding and returns the corresponding Unicode string.
encoding : A string that specifies the character encoding used to encode the input string.
str.decode_utf8
Decodes a UTF-8 encoded string and returns the corresponding Unicode string.
self.deflate
self.die
self.digits
from.downto(to, step)
self.dump
Aliases: inspect
self.each {|char| ... }
Iterates through each character in the string and applies a given block of code to each character.
Aliases: each_char
self.each_byte {|byte| ... }
Iterates through each byte value in the string and applies a given block of code to each byte value.
self.each_graph {|grapheme| ... }
Iterates through each grapheme in the string and applies a given block of code to each grapheme.
Aliases: each_grapheme
self.each_kv(block)
self.each_line {|line| ... }
Iterates through each line in the string and applies a given block of code to each line.
self.each_num {|num| ... }
Iterates through each word, converted to a number, in the string and applies a given block of code to each number.
Aliases: each_number
self.each_slice(n, block)
self.each_word {|word| ... }
Iterates through each word in the string and applies a given block of code to each word.
str.encode(encoding)
Encodes a string into a specified character encoding and returns a new string object.
encoding : A string that specifies the character encoding to be used for encoding the input string.
self.encode_utf8
Encodes a Unicode string using the UTF-8 character encoding and returns a new string object.
str.ends_with(suffix)
Checks if a string ends with a specified suffix and returns a boolean value.
suffix : A string that represents the suffix to be searched for at the end of the input string.
str.escape
Returns a copy of the input string with all non-word characters escaped using a backslash character.
Aliases: quotemeta
self.esub(regex, block)
self.extract_bracketed(brackets)
self.extract_codeblock(delim)
self.extract_delimited(delim)
self.extract_quotelike
self.extract_tagged
str.fc
Returns a copy of the input string with all uppercase characters converted to their lowercase equivalents.
Casefolding is the process of mapping strings to a form where case differences are erased; comparing two strings in their casefolded form is effectively a way of asking if two strings are equal, regardless of case.
Aliases: foldcase
str.first(n)
Returns the first n characters of the input string, where n is an integer.
n : An integer that represents the number of characters to be returned from the beginning of the input string.
str.flip
Returns a copy of the input string with the order of its characters reversed.
Aliases: reverse
self.format
self.frequire
self.gesub(regex, block)
self.glob
self.gmatch(regex, pos)
str.graphs
Returns an Array of grapheme clusters in the input string. A grapheme cluster is a sequence of one or more Unicode code points that represents a single user-perceived character.
Aliases: graphemes
str.graphs_len
Returns the number of grapheme clusters in the input string.
Aliases: graphs_length
self.gsub(regex, str)
Aliases: replace_all
self.gunzip
self.gzip
self.has(substr, pos=0) self.has(regex, pos=0)
Checks if a substring exists within the input string starting from a given position.
substr : A string that represents the substring to search for. pos : An integer that represents the starting position from where to search for the substring. The default value is 0.
When a regular expression is given, it checks if the regular expression pattern matches within the input string starting from a given position.
Aliases: contain, include, contains, includes
self.hex
self.hex2ascii
Decodes a hexadecimal string and returns its equivalent byte-string.
Aliases: unhexlify
self.hexlify
Encodes the input string as a hexadecimal string.
Aliases: ascii2hex
str.index(substr, pos)
Returns the index of the first occurrence of a substring in a given string starting from a specified position.
str : The original string in which the substring is to be searched. substring : The substring to be searched in the original string. pos : The position in the original string from where the search is to begin. The default value is 0.
self.inflate
str.insert(substring, pos, len)
Inserts a substring into a given string at a specified position for a given length.
str : The original string into which the substring is to be inserted. substring : The substring to be inserted into the original string. pos : The position in the original string where the insertion is to begin. len : The length of the original string from the position where the insertion is to begin.
self.ints
Aliases: integers
self.is_alnum
Aliases: is_alphanum
self.is_alpha
self.is_ascii
self.is_blank
self.is_control
self.is_digit
str.is_empty
Determine if a given string is empty or not. It takes a string as an input and returns True if the string is empty, False otherwise.
self.is_graph
self.is_lc
Aliases: is_lowercase
str.is_numeric
Checks whether a given string looks like a number or not. It checks if the string can be converted to a number without raising an exception.
Aliases: looks_like_number
str.is_palindrome
Checks whether a given string is a palindrome or not. A palindrome is a word, phrase, number, or other sequence of characters that reads the same backward as forward.
self.is_printable
self.is_punct
Aliases: is_punctuation
self.is_space
self.is_uc
Aliases: is_uppercase
self.is_word
self.is_xdigit
self.iter
jaro_distance(str1, str2, winkler=false)
Calculates the Jaro distance between two strings. Jaro distance is a measure of similarity between two strings, based on the number of matching characters and transpositions.
When the third argument is true, it returns the Jaro-Winkler distance.
delim.join(strings...)
Concatenates a list of strings and returns a single string, using a specified delimiter.
str.last(n)
Returns the last n characters of a string.
str.lc
Returns a new string with all alphabetic characters converted to lowercase.
Aliases: lower, downcase, lowercase
str.lcfirst
Returns a new string with the first character of the string converted to lowercase.
str.len
Returns the length of the string.
Aliases: size, length, chars_len, chars_length
levenshtein(str1, str2)
Calculates the Levenshtein distance between two strings, which is the minimum number of single-character edits (insertions, deletions, or substitutions) required to transform one string into the other.
Aliases: leven, levenshtein
str.lines
Returns an array of the lines in a string. A line is defined as a sequence of characters terminated by a newline character ("\n") or a carriage return character followed by a newline character ("\r\n").
str.ltrim self.ltrim(regex)
Takes a regular expression regex and removes any substring from the beginning of the string str that matches the regular expression. The resulting string is returned.
When no argument is given, it strips whitespace characters from the beginning of the string.
Aliases: lstrip, trim_beg, strip_beg, trim_left, strip_left
str.md5
Returns the MD5 digest for the given string in hexadecimal form.
Str(args...)
Creates a new string, by concatenating together a given list of objects.
Aliases: call
str.num(base=10)
Returns the numeric representation of the string according to the specified base.
base : An integer representing the numeric base to use for conversion. Valid values for base are between 2 and 62 (inclusive). If not specified, base defaults to 10.
Aliases: to_n, to_num
str.nums
Returns a list of numbers that were found in the string.
The function splits the string by whitespace, and collects every word that looks like a number.
The numbers in the returned list will be in the same order that they appeared in the string.
Aliases: numbers
self.oct
self.open_r(mode)
self.ord
overlaps(str1, str2)
Checks whether there is any overlap between two strings, i.e., whether they have any characters in common. It returns True if there is any overlap, and False otherwise.
self.pack(*list)
str.parse_quotewords(delim, keep)
Parse a string into an Array of words or phrases. It takes a string as an input and returns an Array of words or phrases parsed from the input string. The function can also handle quoted phrases, allowing users to specify phrases containing delimiters.
The method takes three parameters:
str : A string that needs to be split into words. delim : A string that represents the delimiter to be used while splitting the string. The default value is a space character (' '). keep : A Boolean value that indicates whether to keep the quotes around quoted words or not. The default value is False.
self.pipe
str.pop
Returns the last character of the string.
str.prepend(prefix)
Returns a new string with the prefix added to the beginning of the str.
prefix
self.printf(*arguments)
self.printlnf(*arguments)
from.range(to, step)
self.require
self.rindex(substr, pos)
self.rotate(n)
self.rtrim(arg)
Aliases: rstrip, trim_end, strip_end, trim_right, strip_right
method.run(self, *args)
self.scan(regex)
self.sha1
self.sha256
Returns the SHA-256 digest for the given string in hexadecimal form.
str.sha512
Returns the SHA-512 digest for the given string in hexadecimal form.
str.slice(offset) str.slice(offset, length)
Extracts a substring out of the self-string and returns it. First character is at offset zero.
If offset is negative, starts that far back from the end of the string.
offset
If length is omitted, returns everything through the end of the string.
length
If length is negative, leaves that many characters off the end of the string.
Aliases: substr, substring
str.slices(n)
Takes a string and divides it into slices of a specified length. The length of the slice is specified by the integer parameter n. If the length of the string is not evenly divisible by n, the last slice will be shorter than n characters.
self.sort(block)
self.split(sep, size)
self.sprintlnf(*arguments)
self.sub(regex, str)
Aliases: replace
str.tc
Returns a new string where each word in the input string str is capitalized.
Aliases: ucfirst, titlecase
self.tclc
Returns the string with the first character capitalized and the remaining characters in lower case.
Aliases: capitalize
self.to_i
Aliases: to_int
self.to_s
Aliases: to_str
self.tr(orig, repl, modes)
Aliases: translit
self.trans(orig, repl)
self.trim(arg)
Aliases: strip
str.uc
Convert all the characters in a string to uppercase. It takes a string as an input and returns the same string with all the characters converted to uppercase.
Aliases: upper, upcase
str.unescape
Removes backslash escapes from a string. The reverse of the str.escape method.
self.uniq
Aliases: unique, distinct
self.unpack(arg)
self.use
self.warn
self.wc
Change the case of words in a string. It takes a string as an input and returns the same string with the case of each word modified, making the first letter uppercase and the other letters lowercase.
Aliases: wordcase
str.words
Split a string into words. It takes a string as an input and returns an Array of words in the string. A word is defined as a sequence of characters separated by whitespace characters.
To install Sidef, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Sidef
CPAN shell
perl -MCPAN -e shell install Sidef
For more information on module installation, please visit the detailed CPAN module installation guide.