made input into string but it's not showing all the numbers I need

1 visualización (últimos 30 días)
eel
eel el 16 de En. de 2018
Respondida: Darshan Ramakant Bhat el 18 de En. de 2018
I have to extract certain numbers from an input. I turned it into a string to use the extractAfter and extractBefore functions. This is what the code looks like:
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 10 numbers have been removed
%str3 results in the part of ID that is the supposed creation date
While the extracting is working as it should, the string function turns my input into "1.08592017101e+18." When I extract the parts, it doesn't include the other numbers after the "e," which I need. Is there a way to make it into a string without it becoming "1.08592017101e+18" ?

Respuestas (1)

Darshan Ramakant Bhat
Darshan Ramakant Bhat el 18 de En. de 2018
There can be multiple ways to resolve this. One simple way is to using sprintf() to specify the format. The code will be like below:
inputID = input('Please input an ID:');
createDate = input('Please input the creation date in MMDDYYYY format:');
str1 = sprintf('%18d',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
I hope this is what you wanted.

Categorías

Más información sobre Environment and Settings 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