Splitting a string of numbers and '|'
Show older comments
[EDIT: Tue Jun 21 20:43:11 UTC 2011 - Reformat - MKF]
I cant find anything on the help for regexp that gives a way to split up numbers.
I have '1 | 2' and I need to get '1' and '2' as two separate strings.
I am getting this string from a listbox
Pos = get(handles.PositionList,'String')
Reg_num = get(handles.PositionList,'Value')
Reg_num is so that MATLAB knows which line is selected.
Accepted Answer
More Answers (2)
Jan
on 22 Jun 2011
Another solution:
strtrim(regexp('1 | 2', '\|', 'split'))
Walter Roberson
on 21 Jun 2011
Pos = textscan(get(handles.PositionList,'String'), '%d', 'Delimiter', '|');
Pos{1}(get(handles.PostionList,'Value'))
Caution: If I recall correctly, I have seen cases where when you construct a listbox using '|' separated options, that the uicontrol internally converted this into a cell array of strings. It would therefore be more robust to check whether the 'String' returned was indeed ischar() or if it was iscell() instead.
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!