Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Replace multiple characters using strrep
Replies: 2   Last Post: Mar 3, 2014 9:26 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Scott

Posts: 1
Registered: 3/2/14
Replace multiple characters using strrep
Posted: Mar 2, 2014 2:34 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hi everyone,

I'm trying to use 'strrep' to replace multiple characters in a string simultaneously. For instance:

newword=strrep('giant','a','t')

would generate: 'gitnt'

Then if I want to make all of the 't' characters to 'o' characters, the code would be:

newword=strrep(newword,'t','o')

would generate: 'giono'

So I am trying to replace multiple characters in a string simultaneously, so as to say that all of the 'a' characters in the original string are replaced with 't' and all of the 't' characters in the original string are replaced with 'o', for example:

newword=strrep('giant','a','t','t','o')

newword='gitno'

Please help if anyone has a simple solution to this!



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.