📄 mf_subinstr.hlp
字号:
{smcl}
{* 17mar2005}{...}
{cmd:help mata subinstr()}
{hline}
{* index subinstr()}{...}
{* index subinword()}{...}
{title:Title}
{p 4 4 2}
{bf:[M-5] subinstr() -- Substitute text}
{title:Syntax}
{p 8 31 2}
{it:string matrix}
{cmd:subinstr(}{it:string matrix s}{cmd:,}{break}
{it:string matrix old}{cmd:,}
{it:string matrix new}{cmd:,}{break}
{it:real matrix cnt}{cmd:)}
{p 8 31 2}
{it:string matrix}
{cmd:subinstr(}{it:string matrix s}{cmd:,}{break}
{it:string matrix old}{cmd:,}
{it:string matrix new}{cmd:)}
{p 8 32 2}
{it:string matrix}
{cmd:subinword(}{it:string matrix s}{cmd:,}{break}
{it:string matrix old}{cmd:,}
{it:string matrix new}{cmd:,}{break}
{it:real matrix cnt}{cmd:)}
{p 8 32 2}
{it:string matrix}
{cmd:subinword(}{it:string matrix s}{cmd:,}{break}
{it:string matrix old}{cmd:,}
{it:string matrix new}{cmd:)}
{title:Description}
{p 4 4 2}
{cmd:subinstr(}{it:s}{cmd:,} {it:old}{cmd:,} {it:new}{cmd:,} {it:cnt}{cmd:)}
returns {it:s} with the first {it:cnt} occurrences of {it:old} changed to
{it:new}. All occurrences are changed if {it:cnt} contains missing.
{p 4 4 2}
{cmd:subinstr(}{it:s}{cmd:,} {it:old}{cmd:,} {it:new}{cmd:)}
returns {it:s} with all occurrences of {it:old} changed to
{it:new}.
{p 4 4 2}
{cmd:subinword(}{it:s}{cmd:,} {it:old}{cmd:,} {it:new}{cmd:,} {it:cnt}{cmd:)}
returns {it:s} with the first {it:cnt} occurrences of {it:old} on word
boundaries changed to {it:new}. All occurrences are changed if {it:cnt}
contains missing.
{p 4 4 2}
{cmd:subinword(}{it:s}{cmd:,} {it:old}{cmd:,} {it:new}{cmd:)}
returns {it:s} with all occurrences of {it:old} on word boundaries
changed to
{it:new}.
{p 4 4 2}
When arguments are not scalars, these functions return element-by-element
results.
{title:Remarks}
{p 4 4 2}
{cmd:subinstr("th thin man", "th", "the")} returns "the thein man".
{p 4 4 2}
{cmd:subinword("th thin man", "th", "the")} returns "the thin man".
{title:Conformability}
{p 4 4 2}
{cmd:subinstr(}{it:s}{cmd:,} {it:old}{cmd:,} {it:new}{cmd:,} {it:cnt}{cmd:)},
{cmd:subinstr(}{it:s}{cmd:,} {it:old}{cmd:,} {it:new}{cmd:)},{break}
{cmd:subinword(}{it:s}{cmd:,} {it:old}{cmd:,} {it:new}{cmd:,} {it:cnt}{cmd:)},
{cmd:subinword(}{it:s}{cmd:,} {it:old}{cmd:,} {it:new}{cmd:)}:
{p_end}
{it:s}: {it:r1 x c1}
{it:old}: {it:r2 x c2}
{it:new}: {it:r3 x c3}
{it:cnt}: {it:r4 x c4} (optional); {it:s}, {it:old}, {it:new}, {it:cnt} r-conformable
{it:result}: max({it:r1},{it:r2},{it:r3},{it:r4}) {it:x} max({it:c1},{it:c2},{it:c3},{it:c4})
{title:Diagnostics}
{p 4 4 2}
{cmd:subinstr(}{it:s}{cmd:,} {it:old}{cmd:,} {it:new}{cmd:,} {it:cnt}{cmd:)}
and
{cmd:subinword(}{it:s}{cmd:,} {it:old}{cmd:,} {it:new}{cmd:,} {it:cnt}{cmd:)}
treat {it:cnt}<0 as if {it:cnt}=0 was specified; the original string {it:s}
is returned.
{title:Source code}
{p 4 4 2}
Functions are built-in.
{title:Also see}
{p 4 13 2}
Manual: {hi:[M-5] subinstr()}
{p 4 13 2}
Online: help for
{bf:{help m4_string:[M-4] string}}
{p_end}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -