How Can Replacing Characters In A String?

Illustration
Crosby - 2024-09-02T13:35:35+00:00
Question: How Can Replacing Characters In A String?

I want to replace characters in a string using loops and if statements. For example if there is a Y in the string, I want to change it to a J. If there is an M in the string I want to change it to a Q.

Expert Answer

Profile picture of John Williams John Williams answered . 2025-11-20

One example(use regexprep):

s="Yao Ming";
regexprep(s,{'Y','M'},{'J','Q'})


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!