String Functions
SRON provides many string manipulation functions used to work on strings with great speed and performance.
Below are 19 functions to use:
at
count
delete
index
insert
len
push
pop
replace
reverse
reverse_sort
rindex
sort
split
subpart
tolower
toupper
trim
update
1. at():
This function is used to get the 'Char' value at a particular index.
OUTPUT:
e
2. count():
This function is used to count occurrence of 'Char' or 'String' value in parent String.
OUTPUT:
5 2
3. delete():
This function is used to delete a 'Char' value present in a particular index in a String.
OUTPUT:
Hello SRON!
4. index():
This function is used to find the index of first occurrence of a 'Char' value in a String. Returns -1, if character not found.
OUTPUT:
2
5. insert():
This function is used to insert a value into 'String'. It takes 3 arguments: first of type 'String', second of type 'Int' to specify at what index you want to insert the value, and third is the value you want to insert. It returns Void.
OUTPUT:
Hello,Hi SRON!
6. len():
This function is used to get the length of the String.
OUTPUT:
12
7. push():
This function is used to append a new String or Char at the end of the String. It takes two arguments: the String value in which you want to push and another one is a value of any type.
OUTPUT:
Hello, SRON! Hi
8. pop():
This function is used to delete and return the last element of the String. It takes only one argument that is String and returns 'Char' value.
OUTPUT:
! Hello, SRON
9. replace():
This function is used to replace all the occurence of a particular character with another character. It takes three arguments: first is String value, second one is 'Char' value which will be replaced and third one is 'Char' value which will be replacement of second argument.
OUTPUT:
He__o, SRON!
10. reverse():
This function is used to reverse a String. It takes only String as input and returns Void.
OUTPUT:
!NORS ,olleH
11. rindex():
This function is used to get the index of a first character occurrence from the end. It takes two arguments: the String value from which you require to return the value and another argument is a 'Char' value for which you want to find the index. It returns -1, if the character is not found.
OUTPUT:
3
12. sort():
This function is used to sort a String. It returns a Void value.
OUTPUT:
eiopqrtuwy
13. split():
This function is used to split the String on the basis of some character occurence. It returns a list filled with 'String' values.
OUTPUT:
[1, 2, 3, 4, 5, 6, 7, 8, 9]
14. subpart():
This function is used to extract a part of String. It takes 3 arguments: first is the 'String' from which you will extract the substring, then the 'Int' index by which you need to start extraction, then another 'Int' index by which you want to end the extraction.
OUTPUT:
SRON
15. tolower():
This function is used to convert all the alphabets in the String to lowercase.
OUTPUT:
hello, sron!
16. toupper():
This function is used to convert all the alphabets in the String to uppercase.
OUTPUT:
HELLO, SRON!
17. trim():
This function is used to remove the leading and trailing newlines, tabs and spaces.
OUTPUT:
Hello, SRON!
18. update():
This function is used to update a 'Char' value at a particular index.
OUTPUT:
Hello, SRON!
19. reverse_sort():
This function is used to sort a String in reverse order. It returns a Void value.
OUTPUT:
NORS
Last updated