NAME

Sidef::Types::String::String

DESCRIPTION

This class implements ...

SYNOPSIS

var obj = String(...)

INHERITS

Inherits methods from:

* Sidef::Object::Object

METHODS

%

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.

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:

'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).

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.

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.

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.

Parameters:

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

apply_escapes

self.apply_escapes(parser)

Returns the

ascii2bin

str.ascii2bin

Takes a string of ASCII characters as input and returns a string of binary digits representing the ASCII values of the characters.

ascii2bits

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.

backtick

self.backtick

Returns the

base64_decode

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.

Aliases: decode_base64

base64_encode

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.

Aliases: encode_base64

begins_with

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

bin

self.bin

Returns the

bin2ascii

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.

byte

self.byte(pos)

Returns the

Aliases: byte_at

bytes

str.bytes

Convert a string into an Array of bytes, ranging from 0 to 255.

bytes_len

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

center

self.center(size, char)

Returns the

char

self.char(pos)

Returns the

Aliases: char_at

chars

str.chars

Convert a string into an Array of characters.

say "foo".chars     #=> ["f", "o", "o"]

chomp

self.chomp

Returns the

chop

self.chop

Returns the

clear

self.clear

Returns the

codes

str.codes

Convert a string into an Array of code points.

say "foo".codes   #=> [102, 111, 111]
say "€".codes     #=> [8364]

Aliases: code_points

collect

self.collect(regex)

Returns the

Aliases: find_all, findall

cons

self.cons(n)

Returns the

count

self.count(arg)

Returns the

crypt

self.crypt(salt)

Returns the

decode

str.decode(enconding)

Decodes a string using a specified character encoding and returns the corresponding Unicode string.

Parameters:

encoding : A string that specifies the character encoding used to encode the input string.

decode_utf8

str.decode_utf8

Decodes a UTF-8 encoded string and returns the corresponding Unicode string.

deflate

self.deflate

Returns the

die

self.die

Returns the

digits

self.digits

Returns the

downto

from.downto(to, step)

Returns the

dump

self.dump

Returns the

Aliases: inspect

each

self.each {|char| ... }

Iterates through each character in the string and applies a given block of code to each character.

Aliases: each_char

each_byte

self.each_byte {|byte| ... }

Iterates through each byte value in the string and applies a given block of code to each byte value.

each_cons

self.each_cons(n, block)

Returns the

each_graph

self.each_graph {|grapheme| ... }

Iterates through each grapheme in the string and applies a given block of code to each grapheme.

Aliases: each_grapheme

each_kv

self.each_kv(block)

Returns the

each_line

self.each_line {|line| ... }

Iterates through each line in the string and applies a given block of code to each line.

each_num

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

each_slice

self.each_slice(n, block)

Returns the

each_word

self.each_word {|word| ... }

Iterates through each word in the string and applies a given block of code to each word.

encode

str.encode(encoding)

Encodes a string into a specified character encoding and returns a new string object.

Parameters:

encoding : A string that specifies the character encoding to be used for encoding the input string.

encode_utf8

self.encode_utf8

Encodes a Unicode string using the UTF-8 character encoding and returns a new string object.

ends_with

str.ends_with(suffix)

Checks if a string ends with a specified suffix and returns a boolean value.

Parameters:

suffix : A string that represents the suffix to be searched for at the end of the input string.

escape

str.escape

Returns a copy of the input string with all non-word characters escaped using a backslash character.

Aliases: quotemeta

esub

self.esub(regex, block)

Returns the

extract_bracketed

self.extract_bracketed(brackets)

Returns the

extract_codeblock

self.extract_codeblock(delim)

Returns the

extract_delimited

self.extract_delimited(delim)

Returns the

extract_quotelike

self.extract_quotelike

Returns the

extract_tagged

self.extract_tagged

Returns the

fc

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

flip

str.flip

Returns a copy of the input string with the order of its characters reversed.

Aliases: reverse

format

self.format

Returns the

frequire

self.frequire

Returns the

gesub

self.gesub(regex, block)

Returns the

glob

self.glob

Returns the

gmatch

self.gmatch(regex, pos)

Returns the

graphs

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

graphs_len

str.graphs_len

Returns the number of grapheme clusters in the input string.

Aliases: graphs_length

gsub

self.gsub(regex, str)

Returns the

Aliases: replace_all

gunzip

self.gunzip

Returns the

gzip

self.gzip

Returns the

has

self.has(substr, pos=0)
self.has(regex, pos=0)

Checks if a substring exists within the input string starting from a given position.

Parameters:

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

first

str.first(n)

Returns the first n characters of the input string, where n is an integer.

Parameters:

n : An integer that represents the number of characters to be returned from the beginning of the input string.

hex

self.hex

Returns the

hex2ascii

self.hex2ascii

Decodes a hexadecimal string and returns its equivalent byte-string.

Aliases: unhexlify

hexlify

self.hexlify

Encodes the input string as a hexadecimal string.

Aliases: ascii2hex

index

str.index(substr, pos)

Returns the index of the first occurrence of a substring in a given string starting from a specified position.

Parameters:

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.

inflate

self.inflate

Returns the

insert

str.insert(substring, pos, len)

Inserts a substring into a given string at a specified position for a given length.

Parameters:

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.

ints

self.ints

Returns the

Aliases: integers

is_alnum

self.is_alnum

Returns the

Aliases: is_alphanum

is_alpha

self.is_alpha

Returns the

is_ascii

self.is_ascii

Returns the

is_blank

self.is_blank

Returns the

is_control

self.is_control

Returns the

is_digit

self.is_digit

Returns the

is_empty

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.

is_graph

self.is_graph

Returns the

is_lc

self.is_lc

Returns the

Aliases: is_lowercase

is_numeric

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

is_palindrome

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.

is_printable

self.is_printable

Returns the

is_punct

self.is_punct

Returns the

Aliases: is_punctuation

is_space

self.is_space

Returns the

is_uc

self.is_uc

Returns the

Aliases: is_uppercase

is_word

self.is_word

Returns the

is_xdigit

self.is_xdigit

Returns the

iter

self.iter

Returns the

jaro

jaro(str1, str2, winkler=false)

Calculates the Jaro similarity between two strings. Jaro distance is a measure of similarity between two strings, based on the number of matching characters and transpositions.

say jaro("accommodate", "accomodate")         #=> 0.96969696969697

When the third argument is true, it returns the Jaro-Winkler similarity score.

say jaro("accommodate", "accomodate", true)   #=> 0.981818181818182

join

delim.join(strings...)

Concatenates a list of strings and returns a single string, using a specified delimiter.

last

str.last(n)

Returns the last n characters of a string.

lc

str.lc

Returns a new string with all alphabetic characters converted to lowercase.

Aliases: lower, downcase, lowercase

lcfirst

str.lcfirst

Returns a new string with the first character of the string converted to lowercase.

len

str.len

Returns the length of the string.

Aliases: size, length, chars_len, chars_length

lev

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

lines

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").

ltrim

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

md5

str.md5

Returns the MD5 digest for the given string in hexadecimal form.

new

Str(args...)

Creates a new string, by concatenating together a given list of objects.

Aliases: call

num

str.num(base=10)

Returns the numeric representation of the string according to the specified base.

Parameters:

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

nums

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

oct

self.oct

Returns the

open_r

self.open_r(mode)

Returns the

ord

self.ord

Returns the

overlaps

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.

pack

self.pack(*list)

Returns the

parse_quotewords

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.

pipe

self.pipe

Returns the

pop

str.pop

Returns the last character of the string.

prepend

str.prepend(prefix)

Returns a new string with the prefix added to the beginning of the str.

printf

self.printf(*arguments)

Returns the

range

from.range(to, step)

Returns the

require

self.require

Returns the

rindex

self.rindex(substr, pos)

Returns the

rotate

self.rotate(n)

Returns the

rtrim

self.rtrim(arg)

Returns the

Aliases: rstrip, trim_end, strip_end, trim_right, strip_right

run

method.run(self, *args)

Returns the

sayf

self.sayf(*arguments)

Returns the

Aliases: printlnf

scan

self.scan(regex)

Returns the

sha1

self.sha1

Returns the

sha256

self.sha256

Returns the SHA-256 digest for the given string in hexadecimal form.

sha512

str.sha512

Returns the SHA-512 digest for the given string in hexadecimal form.

slice

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.

If length is omitted, returns everything through the end of the string.

If length is negative, leaves that many characters off the end of the string.

Aliases: substr, substring

slices

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.

sort

self.sort(block)

Returns the

split

self.split(sep, size)

Returns the

sprintlnf

self.sprintlnf(*arguments)

Returns the

sub

self.sub(regex, str)

Returns the

Aliases: replace

tc

str.tc

Returns a new string where each word in the input string str is capitalized.

Aliases: ucfirst, titlecase

tclc

self.tclc

Returns the string with the first character capitalized and the remaining characters in lower case.

Aliases: capitalize

to_i

self.to_i

Returns the

Aliases: to_int

to_s

self.to_s

Returns the

Aliases: to_str

tr

self.tr(orig, repl, modes)

Returns the

Aliases: translit

trans

self.trans(orig, repl)

Returns the

trim

self.trim(arg)

Returns the

Aliases: strip

uc

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

unescape

str.unescape

Removes backslash escapes from a string. The reverse of the str.escape method.

uniq

self.uniq

Returns the

Aliases: unique, distinct

unpack

self.unpack(arg)

Returns the

use

self.use

Returns the

warn

self.warn

Returns the

wc

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

words

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.