MOCKSTACKS
EN
Questions And Answers

More Tutorials









Swift strcut


strcut(input,pattern) will match the regular expression in the pattern parameter against the supplied input string and return the section that matches the first matching parenthesised group.

For example:


string t = "my name is John and i like puppies.";
string name = strcut(t, "my name is ([^ ]*) ");
string out = strcat("Your name is ",name);
trace(out);

This will output the message: Your name is John.

strjoin


strjoin(array, delimiter) will combine the elements of an array into a single string separated by a given delimiter. The array passed to strjoin must be of a primitive type (string, int, float, or boolean). It will not join the contents of an array of files.

Example:


string test[] = ["this", "is", "a", "test" ];
string mystring = strjoin(test, " ");
tracef("%s\n", mystring);

This will print the string "this is a test".

strsplit


strsplit(input,pattern) will split the input string based on separators that match the given pattern and return a string array.

Example:


string t = "my name is John and i like puppies.";
string words[] = strsplit(t, "\\s");
foreach word in words {
trace(word);
}

This will output one word of the sentence on each line (though not necessarily in order, due to the fact that foreach iterations execute in parallel).

toInt


toInt(input) will parse its input string into an integer. This can be used with arg() to pass input parameters to a Swift script as integers.

toFloat


toFloat(input) will parse its input string into a floating point number. This can be used with arg() to pass input parameters to a Swift script as floating point numbers.

toString


toString(input) will parse its input into a string. Input can be an int, float, string, or boolean.

Conclusion

In this page (written and validated by ) you learned about Swift strcut . What's Next? If you are interested in completing Swift tutorial, your next topic will be learning about: Swift trace.



Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: mockstacks@gmail.com.


Share On:


Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using Mockstacks.com, you agree to have read and accepted our terms of use, cookies and privacy policy.