does anyone know why my output doen't have space between two words

댓글 수: 11

Brent Kostich
Brent Kostich 2020년 5월 28일
What exactly are the inputs twisted4 and seg4?
Brent Kostich
Brent Kostich 2020년 5월 28일
More to your question, strcat removes any trailing white-space. If you have trailing white-space use horzcat instead. My guess is that you don't have any leading or trailing white-space, in which case you will have to add it into the looping routine.
Maria
Maria 2020년 5월 28일
oh my question is add the space white between words. Because the Expected value is i love georgia tech" But my answer is "i lovegeorgiatech"
Brent Kostich
Brent Kostich 2020년 5월 28일
What exactly is your function supposed to do?
Maria
Maria 2020년 5월 28일
its just given a string that is scrambled up and a segment of the string, representing the scrambled part. The string can be unscrambled by moving the segment given to the end of the string. Locate where the segment is in the string. Then, delete that segment and append it to the end of the string to "untwist" it.
Brent Kostich
Brent Kostich 2020년 5월 28일
I think I understand what you are trying to do, but I think you need more code to achieve your desired result. If you give me an example for str and segment I can show you the fix.
Maria
Maria 2020년 5월 28일
I dont know about this. But there is a test case
untwisted = tongueTwister('Raodp G ', 'od')
untwisted → Rap God
Brent Kostich
Brent Kostich 2020년 5월 28일
편집: Brent Kostich 2020년 5월 28일
That example works because all you need to do is move the 'od' to the end.
If you removed the space so it was 'RaodpG', then your anwer would be 'RapGod'
The function would only work on very specific cases, it would not work on general cases.
Maria
Maria 2020년 5월 28일
So this is right?
Brent Kostich
Brent Kostich 2020년 5월 28일
Did you not write this function? If you are asking me if your own test case is right, then I take it you have no idea what that code is doing.
If that is true, then no one can help you.
Maria
Maria 2020년 5월 29일
gotcha it. I used horzcat instead of stracat and it works ! thanks !

댓글을 달려면 로그인하십시오.

답변 (2개)

Fangjun Jiang
Fangjun Jiang 2020년 5월 28일

0 개 추천

From "help strcat"
For character array inputs, strcat removes trailing ASCII white-space
characters: space, tab, vertical tab, newline, carriage return, and
form-feed. To preserve trailing spaces when concatenating character
arrays, use horizontal array concatenation, [s1, s2, ..., sN]
Steven Lord
Steven Lord 2020년 5월 28일

0 개 추천

You can use concatenation as Fangjun Jiang and Brent Kostich suggested. I'd probably use join instead.
join(["I", "love", "Georgia", "Tech"])

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2020년 5월 28일

댓글:

2020년 5월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by