Previous Page Next Page Contents

stringlib::subs -- Substitution in a string

Introduction

stringlib::subs substitutes a substring by another string.

Call(s)

stringlib::subs(string, substring = replacement, <First>)

Parameters

string - non empty string
substring - non empty string that should be replaced
replacement - any string that replaced substring

Options

First - determines, that only the first appearance of substring in string will be replaced

Returns

the given string with substring replaced by replacement

Related Functions

subs, stringlib::subsop, stringlib::pos, stringlib::remove

Details

Example 1

The string replacement may be empty.

>> stringlib::subs("abcdeabcdeabcde", "bc" = "")
                                "adeadeade"

Example 2

Every substring is replaced unless the option First is given.

>> stringlib::subs("abcdeabcdeabcde", "bc" = "xxx")
                           "axxxdeaxxxdeaxxxde"
>> stringlib::subs("abcdeabcdeabcde", "bc" = "xxx", First)
                            "axxxdeabcdeabcde"

Example 3

The substitution may produce a new instance of substring, but this one is not replaced.

>> stringlib::subs("aab", "ab"="b")      
                                   "ab"

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000