summaryrefslogtreecommitdiffstats
path: root/helpcontent2/source/text/sbasic/shared/replace.xhp
blob: 091a2f08267d546af7548066d565a20760bc1f69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?xml version="1.0" encoding="UTF-8"?>
<helpdocument version="1.0">
    <!--
    * This file is part of the LibreOffice project.
    *
    * This Source Code Form is subject to the terms of the Mozilla Public
    * License, v. 2.0. If a copy of the MPL was not distributed with this
    * file, You can obtain one at http://mozilla.org/MPL/2.0/.
    *
    -->

    <meta>
        <topic id="sbasicsharedreplace" indexer="include" status="PUBLISH">
            <title id="tit" xml-lang="en-US">Replace Function</title>
            <filename>/text/sbasic/shared/replace.xhp</filename>
        </topic>
    </meta>
    <body>
    <section id="replace">
        <bookmark xml-lang="en-US" branch="index" id="bm_id721552551162491">
            <bookmark_value>Replace function</bookmark_value>
        </bookmark>
        <h1 id="hd_id781552551013521"><link href="text/sbasic/shared/replace.xhp" name="Replace Function">Replace Function</link></h1>
        <paragraph id="par_id291552551013522" role="paragraph">Replaces some string by another.</paragraph>
    </section>

    <embed href="text/sbasic/shared/00000003.xhp#functsyntax"/>
    <bascode>
       <paragraph role="bascode" localize="false" id="bas_id51623159758550">Replace (Expression As String, Find As String, Replace As String [, Start = 1 [, Count = -1 [, Compare = True]]]) As String</paragraph>
    </bascode>
    <embed href="text/sbasic/shared/01020300.xhp#kwargs"/>
    <embed href="text/sbasic/shared/00000003.xhp#functvalue"/>
    <paragraph role="paragraph" id="par_id911552552252024">String</paragraph>

    <embed href="text/sbasic/shared/00000003.xhp#functparameters"/>
    <paragraph role="paragraph" id="par_id721552552263062"><emph>Expression:</emph> Any string expression that you want to modify.</paragraph>
    <paragraph role="paragraph" id="par_id901552552269836"><emph>Find:</emph> Any string expression that shall be searched for.</paragraph>
    <paragraph role="paragraph" id="par_id791552552275383"><emph>Replace:</emph> Any string expression that shall replace the found search string.</paragraph>
    <paragraph role="paragraph" id="par_id111552552283060"><emph>Start:</emph> Optional numeric expression that indicates the character position where the search starts and also the start of the substring to be returned.</paragraph>
    <paragraph role="paragraph" id="par_id921552552289833"><emph>Count:</emph> Optional maximum number of times the replace shall be performed. When set to -1, all possible replacements are performed.</paragraph>
    <paragraph role="paragraph" id="par_id891552552302894"><emph>Compare:</emph> Optional boolean expression that defines the type of comparison. The value of this parameter can be <literal>True</literal> or <literal>False</literal>. The default value of <literal>True</literal> specifies a text comparison that is not case-sensitive. The value of <literal>False</literal> specifies a binary comparison that is case-sensitive. You can as well use 0 instead of <literal>False</literal> or 1 instead of <literal>True</literal>.</paragraph>

    <embed href="text/sbasic/shared/00000003.xhp#errorcode"/>
    <embed href="text/sbasic/shared/00000003.xhp#err5"/>
    <embed href="text/sbasic/shared/00000003.xhp#functexample"/>

    <bascode>
        <paragraph role="bascode" id="par_id991552552420717">MsgBox Replace ("aBbcnnbnn", "b", "$", 1, 1, False)  'returns "aB$cnnbnn"</paragraph>
        <paragraph role="bascode" id="par_id321552552440672" xml-lang="en-US">REM meaning: "b" should be replaced, but</paragraph>
        <paragraph role="bascode" id="par_id571552552467647" xml-lang="en-US">REM * only when lowercase (compare=False), hence second occurrence of "b"</paragraph>
        <paragraph role="bascode" id="par_id71552552474769" xml-lang="en-US">REM * only first (respecting case) occurrence (count=1)</paragraph>
        <paragraph role="bascode" id="par_id501587778372566" localize="false">MsgBox Replace ("ABCDEFGHI", "E", "*", 4)</paragraph>
        <paragraph role="bascode" id="par_id861587778446685" xml-lang="en-US">REM returns D*FGHI because the search starts at position 4, which is also the start of the returned string.</paragraph>
        <paragraph role="bascode" id="bas_id491622734884707" xml-lang="en-US">MsgBox Replace("aBbcnnbnn", "b", "$£", compare:=False)  'returns "aB$£cnn$£nn"</paragraph>
        <paragraph role="bascode" id="bas_id341622734993202" xml-lang="en-US">REM Replace all (count = -1) "b" with "$£" respecting casing (compare=False) starting from first letter (start=1) </paragraph>
    </bascode>
    <section id="relatedtopics">
        <paragraph role="paragraph" id="par_id161599082457466" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#stringfunctions"/></paragraph>
        <paragraph role="paragraph" id="par_id361623159933508" localize="false"><embedvar href="text/sbasic/shared/03/sf_string.xhp#StringService"/></paragraph>
    </section>
</body>
</helpdocument>