cxsl string - SkycoinWikis/CXSL GitHub Wiki

CXSL HOME » CX » CXSL » STRING PACKAGE

string package

To use the string-functions you first have to import it:

import "string"

Table of Contents

string.strsub

With this function you can extract a substring from a given string

string.strsub(parent_string str, start_index i32, end_index i32)(sub_string str)
Example
//string.strsub
////input
var parent_string str = "teststring"
var start_index i32 = 2
var end_index i32 = 5
////output
var sub_string str
////function call
sub_string = string.strsub(parent_string, start_index, end_index)

string.strocc

With this function you can check if a substring is within the given string

string.strocc(parent_string str, sub_string str)(is_found bool)
Example
//string.strocc
////input
var parent_string str = "teststring"
var sub_string str = "tst"
////output
var is_found bool
////function call
is_found = string.strocc(parent_string, sub_string)

string.strfind

With this function you get the index of a substring inside a parentstring

string.strfind(parent_string str, sub_string str)(index_of_sub_string i32)
Example
//string.strfind
////input
var parent_string str = "teststring"
var sub_string str = "str"
////output
var index_of_sub_string i32
////function call
index_of_sub_string = string.strfind(parent_string, sub_string)

string.strapp

With this function you can add a string at the end of another string

string.strapp(original_string str, string_to_add_after str)(combined_string str)
Example
//string.strapp
////input
var original_string str = "test"
var string_to_add_after str = "string"
////output
var combined_string str
////function call
combined_string = string.strapp(original_string , string_to_add_after )

string.strpre

With this function you can add a string in front of another string

string.strpre(original_string str, string_to_add_before str)(combined_string str)
Example
//string.strapp
////input
var original_string str = "test"
var string_to_add_before str = "string"
////output
var combined_string str
////function call
combined_string = string.strpre(original_string , string_to_add_before)

string.strsplit

With this function you can split a string into an string array depending on the split argument

string.strsplit(original_string str, argument_string str)(string_parts []str)
Example
//string.strsplit
////input
var parent_string str = "test string with spaces"
var argument_string str = " "
////output
var string_parts_array []str
////function call
string_parts_array = string.strsplit(parent_string, argument_string)

string.strjoin

With this function you can join an array of strings into one string glued with the glue_string

string.strjoin(string_parts_array []str, glue_string str)(string_parts []str)
Example
//string.strjoin
////input
var string_parts []str = []str{"test","string","parts","to","put","together"}
var glue_string str = " "
////output
var joined_string str
////function call
joined_string = string.strjoin(string_parts, glue_string)
⚠️ **GitHub.com Fallback** ⚠️