adding charecters to a string

How can I add a charecter or an element into a string.
for exaple I have the word 'sTudent' I need to add the letter B after each letter in the word
wich means I should have a an aswer 'sBTBuBdBeBnBt'
a string is just a word without spaces.
it has to be added but not after the last letter in the word as it shown in the example.
please help me!

 Respuesta aceptada

Walter Roberson
Walter Roberson el 25 de Dic. de 2018

0 votos

T = regexprep('sTudent', '.', '$&B')
or
T = 'sTudent';
T(2,:) = 'B';
T = reshape(T, 1, []);

3 comentarios

aya qassim
aya qassim el 25 de Dic. de 2018
Editada: aya qassim el 25 de Dic. de 2018
thank you it worked but I don't want it to add after the last letter, how can I fix that?
T = regexprep('sTudent', '.(?=.)', '$&B')
or
T = 'sTudent';
T(2,:) = 'B';
T = reshape(T, 1, []);
T(end) = [];
aya qassim
aya qassim el 25 de Dic. de 2018
thank you very much:)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Centro de ayuda y File Exchange.

Preguntada:

el 25 de Dic. de 2018

Comentada:

el 25 de Dic. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by