-
Notifications
You must be signed in to change notification settings - Fork 3
Primitive Methods
You can not only call methods on objects, but also on some primitive types. These are:
- String
- List
- Dictionary
Here is a list for all of them:
Returns the length of the string.
new my_string "Hello, World!"
my_string.length()
12
Returns the first character of the string.
new my_string "Hello, World!"
my_string.front()
"H"
Returns the last character of the string.
new my_string "Hello, World!"
my_string.back()
"!"
Returns the character of the string at a given index.
new my_string "Hello, World!"
my_string.at(4)
"o"
Errors if the string is empty.
Errors if the index is invalid.
Inserts a character to a given position in the string.
new my_string "Hello, World!"
my_string.insert(12,"?")
print my_string
"Hello, World?!"
Errors if the string is empty.
Errors if the index is invalid.
Replace a character in the string with a given sequence.
new my_string "Hello, World!"
my_string.replace(0,"h")
my_string.replace(12,"??")
print my_string
"hello, World??"
Errors if the string is empty.
Errors if the index is invalid.
Erases a character at a given position in the string.
new my_string "Hello, World!"
my_string.erase(3)
print my_string
"Helo, World!"
Errors if the string is empty.
Errors if the index is invalid.
Erases the first character of the string.
new my_string "Hello, World!"
my_string.pop_front()
print my_string
"ello, World!"
Errors if the string is empty.
Erases the last character of the string.
new my_string "Hello, World!"
my_string.pop_back()
print my_string
"Hello, World"
Errors if the string is empty.
Adds a character to the end of the string.
new my_string "Hello, World!"
my_string.push_back("!")
print my_string
"Hello, World!!"
Returns 1 it the string contains the given character, 0 if else.
new my_string "Hello, World!"
my_string.has(",")
my_string.has("i")
1
0
Returns the amount of characters matching the given character.
new my_string "Hello, World!"
my_string.count("l")
my_string.count("i")
my_string.count("W")
2
0
1
Returns 1 if the string is empty, 0 if else.
new my_string "Hello, World!"
my_string.empty()
set my_string ""
my_string.empty()
0
1
Turns all letters in the string to their uppercase version.
new my_string "Hello, World!"
my_string.to_upper()
print my_string
HELLO, WORLD!
Turns all letters in the string to their lowercase version.
new my_string "Hello, World!"
my_string.to_lower()
print my_string
hello, world!
Returns the length of the list.
new my_list [1,"2",[3,4]]
my_list.length()
3
Returns the first element of the list.
new my_list [1,"2",[3,4]]
my_list.front()
1
Errors if the list is empty.
Returns the last element of the list.
new my_list [1,"2",[3,4]]
my_list.front()
[3,4]
Errors if the list is empty.
Returns the element of the list at a given index.
new my_list [1,"2",[3,4]]
my_list.at(1)
"2"
Errors if the list is empty.
Errors if the index is invalid.
Inserts a value to a given position in the list.
new my_list [1,"2",[3,4]]
my_list.insert(1,"my dear")
print my_list
[1,"my dear","2",[3,4]]
Errors if the list is empty.
Errors if the index is invalid.
Replaces an element in the list with a given value.
new my_list [1,"2",[3,4]]
my_list.replace(1,"5")
print my_list
[1,"5",[3,4]]
Errors if the list is empty.
Errors if the index is invalid.
Erases an element in the list.
new my_list [1,"2",[3,4]]
my_list.erase(0)
print my_list
["2",[3,4]]
Errors if the list is empty.
Errors if the index is invalid.
Erases the first element in the list.
new my_list [1,"2",[3,4]]
my_list.pop_front()
print my_list
["2",[3,4]]
Errors if the list is empty.
Erases the last element in the list.
new my_list [1,"2",[3,4]]
my_list.pop_back()
print my_list
[1,"2"]
Errors if the list is empty.
Adds a value to the end of the list.
new my_list [1,"2",[3,4]]
my_list.push_back(5)
print my_list
[1,"2",[3,4],5]
Returns 1 if the list has the given value and 0 if not.
new my_list [1,"2",[3,4]]
my_list.has(1)
my_list.has(12)
1
2
Returns the amount of elements matching the given value.
new my_list [1,"2",[3,4],"2"]
my_list.count("2")
my_list.count(1)
my_list.count(5)
1
2
0
Returns 1 if there are no elements in the list and 0 if else.
new my_list [1,"2",[3,4]]
my_list.empty()
set my_list []
my_list.empty()
0
1
Sorts the list.
new my_list ["ab",4,1,"ac","a",[4,5],[3]]
my_list.sort()
print my_list
[1,4,"a","ab","ac",[3],[4,5]]
It is sorted by:
- Number
-- small to big - String
-- lowest size to greatest size
-- lowest ascii value to greatest ascii value - List
-- lowest size to greatest size
Returns a sorted version of the list.
new my_list ["ab",4,1,"ac","a",[4,5],[3]]
my_list.sorted()
print my_list
[1,4,"a","ab","ac",[3],[4,5]]
["ab",4,1,"ac","a",[4,5],[3]]
Returns the amount of key/value -pairs
new my_dic {
a = 12,
b = "hihi",
c = 42
}
my_dic.length()
3
Sets a key to a value.
new my_dic {
a = 12,
b = "hihi",
c = 42
}
my_dic.set(c,3)
my_dic.set(d,"huh")
print my_dic
{a = 12,b = "hihi",c = 3,d = "huh"}
Retruns a value based of a given key.
new my_dic {
a = 12,
b = "hihi",
c = 42
}
my_dic.get(c)
42
Returns a list of all keys.
new my_dic {
a = 12,
b = "hihi",
7 = 42
}
my_dic.keys()
["a","b",7]
Returns a list of all values.
new my_dic {
a = 12,
b = "hihi",
7 = 42
}
my_dic.values()
[12,"hihi",42]