Can't get circshift to work for a string?

I have an input that's converted to a string. I extract parts of the string until it's the numbers I need. I need to shift the numbers in this new string by 4, but the circshift function isn't working?
inputID = input('Please input an ID:');
createDate = input('Please input the creation date in MMDDYYYY format:');
str1 = string(inputID)
%str1 is equal to the numbers of the inputted ID
str2 = extractAfter(str1,5)
%str2 is the ID after the first 5 numbers have been removed
str3 = extractBefore(str2,9)
%str3 is the str2 after the last 9 numbers have been removed
%str3 results in the part of ID that is the supposed creation date
str4 = circshift(str3,4,1)
%str4 is str3 shifted so that it matches the format of the creation date
%takes a string of YYYYMMDD format and shifts it 4 characters to the right
%should end up MMDDYYYY format
I know it works through str3 step, but I'm not sure why the circshift isn't working. After running it, it continues to output str4 as exactly the same as str3.

Antworten (1)

Walter Roberson
Walter Roberson am 15 Jan. 2018

0 Stimmen

circshift affects elements in an array. string() creates a string array, with each element being one string. It is the string array that you are circshift()'ing. To circshift the characters you will need to extract them from the string. For example,
str4 = string( circshift(str3{1}, 4, 1) );

2 Kommentare

eel
eel am 16 Jan. 2018
I replaced my str4 line of code with this, and it still did not work, outputting the same thing it did before I tried this.
str4 = string( circshift(str3{1}, [1 4]) );

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Characters and Strings finden Sie in Hilfe-Center und File Exchange

Gefragt:

eel
am 15 Jan. 2018

Kommentiert:

am 16 Jan. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by