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

2 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Image Analyst
Image Analyst el 29 de En. de 2017
Try this:
word = 'abcdefgh'
middleIndexes = randperm(length(word)-2) + 1
newWord = [word(1), word(middleIndexes), word(end)]

Más respuestas (2)

Stephen23
Stephen23 el 29 de En. de 2017
>> 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 el 29 de En. de 2017
Editada: Jan el 29 de En. de 2017
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.

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by