How to write a program, and shuffles only the inner letter of the word?

4 ビュー (過去 30 日間)
ana zong
ana zong 2017 年 1 月 29 日
コメント済み: Rena Berman 2017 年 1 月 30 日
How to write a program, and shuffles only the inner letter of the word, but leave the first and last letter of the word alone? Thank you

採用された回答

Image Analyst
Image Analyst 2017 年 1 月 29 日
Try this:
word = 'abcdefgh'
middleIndexes = randperm(length(word)-2) + 1
newWord = [word(1), word(middleIndexes), word(end)]

その他の回答 (2 件)

Stephen23
Stephen23 2017 年 1 月 29 日
>> str = 'This is really quite easy with regular expressions.';
>> regexprep(str,'(\w)(\w+)(\w)','$1${$2(randperm(numel($2)))}$3')
ans =
Tihs is rlleay qiute esay with rlgaeur esiorsxpens.

Jan
Jan 2017 年 1 月 29 日
編集済み: Jan 2017 年 1 月 29 日
Acoicdnrg to a stduy of an Enlsigh unitsvreiy the odrer of carartehcs in a wrod deos not prevnet the riatdibaley, as lnog as the fsirt and lsat chetcraar are ccroert. The rset can be ctpemoelly mxeid and nsnneose, but it is sitll rdaleabe. Tihs wrkos, beasuce the wrdos are not raed certcaahr by ccrataher, but iifdnetied in toatl.
  2 件のコメント
ana zong
ana zong 2017 年 1 月 29 日
thank you!
Rena Berman
Rena Berman 2017 年 1 月 30 日
Jan that is cool!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by