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

4 次查看(过去 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 CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by