How do you change the asterisks in the first string to the characters in the same positions in the second string?

2 ビュー (過去 30 日間)
I have two strings for example
string1 = 'v**de***t'
string2 = 'eolehmors'
The outcome should be
out = 'voldemort'
Please do not hard code.
*Note: the input strings will always be the same length

採用された回答

Karim
Karim 2022 年 9 月 23 日
編集済み: Karim 2022 年 9 月 23 日
See below for one method.
string1 = 'v**de***t';
string2 = 'eolehmors';
% find location of the asterisks
idx = string1 == '*';
% copy string1
out = string1;
% replace asterisks with data from string2
out(idx) = string2(idx)
out = 'voldemort'

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by