Matlabの文字列検索(findstr)と置換(strrep)



Matlab String Search



1.機能機能:

findstr(s1、s2):長い文字列内の短い文字列の位置を返します。

strrep(s1、s2、s3):文字列s1のすべての部分文字列s2をs3に置き換えます。



2.コード例:

clc clear all s1 = 'mmmatlabmatlab' s2 = 'mat' findstr(s1,s2) %Find the position of the short string in the long string, the positions of s1 and s2 are interchangeable s3 = strrep(s1,s2,'MAT')% Replace the mat in s1 with MAT and store it in s3

演算結果:

年=



3 9


s3 =

mmMATlabMATlab