PickBASIC / FlashBASIC
swap() function
.mdThe swap() function searches a str.exp for the search.str. If the search.str is at the start occurrence, then replacement.str replaces search.str for the amount specified in occurrences.
Synonymsereplace()change()
Syntax
swap(str.exp, search.str, replacement.str {,occurrences{,start}})Parameter(s)
| str.exp | String in which the specified search.str is searched. |
| search.str | String to search for in str.exp. |
| replacement.str | String to replace the specified search.str. |
| occurrences | Specifies the number of occurrences of search.str to be replaced by replacement.str. If not specified, the default is 0, which replaces all found occurrences. |
| start | Specifies on which occurrence of search string the
replacement begins. If not specified, the default is 1. |
Example(s)
Example 1
This code assigns the value "The old time" to nstring.
nstring = swap("The new time","new","old")
Example 2
This code outputs "++-". The swap() function replaces
two occurrences of "-" starting at the first occurrence.
print swap("---","-","+",2,1)
Replace every occurrence of a substring
print swap("a-b-c", "-", "/") ;* a/b/c