Ahmed - I think that you may want to manage, outside of the list box, a separate list of all the strings that have been added to the list box and a count of each time that string has been added. This could be a cell array with two columns: the first being the strings, and the second being a count of each string. When the user presses the Add button, the code would compare against each string in the first column of your cell array. If a match is found, then the second column is incremented by one. If no match is found, then the string is added to the cell array (in the first column) with a zero (or one) count (in the second column). You would then add this string to the list box, adding the numeric suffix if needed.
I suppose an alternative to a cell array is a map with the key being the input string.
Note that how you store and use this cell array (or whatever container you decided to use) depends upon how you have coded your GUI (with GUIDE, programmtically, or with App Designer).
2 Comments
Direct link to this comment
https://nl.mathworks.com/matlabcentral/answers/503528-adding-strings-to-list-box-so-that-if-two-strings-are-same-a-number-will-be-added#comment_793427
Direct link to this comment
https://nl.mathworks.com/matlabcentral/answers/503528-adding-strings-to-list-box-so-that-if-two-strings-are-same-a-number-will-be-added#comment_793427
Direct link to this comment
https://nl.mathworks.com/matlabcentral/answers/503528-adding-strings-to-list-box-so-that-if-two-strings-are-same-a-number-will-be-added#comment_793464
Direct link to this comment
https://nl.mathworks.com/matlabcentral/answers/503528-adding-strings-to-list-box-so-that-if-two-strings-are-same-a-number-will-be-added#comment_793464
Sign in to comment.