</head> <body> <h1>StrReplace() <span class="ver">[v1.1.21+]</span></h1> <p>Replaces the specified substring with a new string.</p> <pre class="Syntax">ReplacedStr := <span class="func">StrReplace</span>(Haystack, Needle <span class="optional">, ReplaceText, OutputVarCount, Limit</span>)</pre> <h2 id="Parameters">Parâmetros</h2> <dl> <dt>Haystack</dt> <dd>The string whose content is searched and replaced.</dd> <dt>Needle</dt> <dd>The string to search for. Matching is not case sensitive unless <a href="StringCaseSense.htm">StringCaseSense</a> has been turned on.</dd> <dt>ReplaceText</dt> <dd><em>Needle</em> will be replaced with this text. If omitted or blank, <em>Needle</em> will be replaced with blank (empty). In other words, it will be omitted from the return value.</dd> <dt>OutputVarCount</dt> <dd>Specify a output variable in which to store the number of replacements that occurred (0 if none).</dd> <dt>Limit</dt> <dd>If omitted, it defaults to -1, which replaces <strong>all</strong> occurrences of the pattern found in <em>Haystack</em>. Otherwise, specify the maximum number of replacements to allow. The part of <em>Haystack</em> to the right of the last replacement is left unchanged.</dd> </dl> <h2 id="Return_Value">Return Value</h2> <p>This function returns a version of <em>Haystack</em> whose contents have been replaced by the operation. If no replacements are needed, <em>Haystack</em> is returned unaltered.</p> <h2 id="Remarks">Remarks</h2> <p>The built-in variables <a href="../Variables.htm">A_Space</a> and <a href="../Variables.htm">A_Tab</a> contain a single space and a single tab character, respectively. They are useful when searching for spaces and tabs alone or at the beginning or end of <em>Needle</em>.</p> <h2 id="Related">Tópicos relacionados</h2> <p><a href="StringReplace.htm">StringReplace</a>, <a href="RegExReplace.htm">RegExReplace()</a>, <a href="InStr.htm">InStr()</a>, <a href="StringCaseSense.htm">StringCaseSense</a>, <a href="SubStr.htm">SubStr()</a>, <a href="Trim.htm">Trim()</a>, <a href="StrLen.htm">StrLen()</a>, <a href="StringLower.htm">StringLower</a>, <a href="StringLower.htm">StringUpper</a></p> <h2 id="Examples">Exemplos</h2> <div class="ex" id="ExClipboard"> <p><a class="ex_number" href="#ExClipboard"></a> Removes all CR+LF's from the clipboard contents.</p> <pre>Clipboard := StrReplace(Clipboard, "`r`n")</pre> </div> <div class="ex" id="ExVar"> <p><a class="ex_number" href="#ExVar"></a> Replaces all spaces with pluses.</p> <pre>NewStr := StrReplace(OldStr, A_Space, "+")</pre> </div> <div class="ex" id="ExRemoveBlankLines"> <p><a class="ex_number" href="#ExRemoveBlankLines"></a> Removes all blank lines from the text in a variable.</p> <pre>Loop { MyString := StrReplace(MyString, "`r`n`r`n", "`r`n", Count) if (Count = 0) <em>; No more replacements needed.</em> break }</pre> </div> </body> </html>