How to join character

1 visualizzazione (ultimi 30 giorni)
Pat
Pat il 27 Mar 2016
Commentato: Walter Roberson il 28 Mar 2016
I have a string, after preprocessing i get result as
str=Institution/College
Name;
When i split the string using
str1=regexp(str, '/', 'split')
i get result as [1x11 char] [1x11 char]
str2{2}
gives
College
Name
i need as College Name, i need in one line as College Name
Kindly help

Risposte (3)

Image Analyst
Image Analyst il 27 Mar 2016
Well don't split it then. Or is the word Institution followed by a slash there and you just want to get rid of that?
str = 'Institution/College Name';
slashLocation = strfind(str, '/');
newStr = str(slashLocation+1:end) % Gives 'College Name'
  6 Commenti
Walter Roberson
Walter Roberson il 28 Mar 2016
find_system does not split the subsystem names at blanks. It returns a cell array of strings, each with one name. The adjacent entries do not belong together.
It sounds to me as if you have a carriage return (or newline) in a subsystem name. Historically that was not permitted. If it is permitted now, then the carriage return (or newline) would be part of the name and so the name should not be merged onto one line.
Walter Roberson
Walter Roberson il 28 Mar 2016
It appears that under some conditions, spaces and newlines are now permitted; http://www.mathworks.com/help/simulink/ug/accessing-signal-logging-data.html#budgyrh . However, they would still be part of the name. It would be valid to have a signal named 'College Name' (with a space) and a signal named ['College' char(10) 'Name'] (with a newline) in the same block, so putting them on the same line would be misrepresenting the name.

Accedi per commentare.


KSSV
KSSV il 27 Mar 2016
Doc strcat
  1 Commento
Pat
Pat il 27 Mar 2016
sorry str2{2} gives
College
Name
i need as College Name,strcat doesn't provide result i tried using strcat ,but the result is one string in two lines,i need in one line

Accedi per commentare.


Stephen23
Stephen23 il 28 Mar 2016
Modificato: Stephen23 il 28 Mar 2016
>> old = sprintf('Institution/College\nName')
old = Institution/College
Name
>> new = regexp(regexprep(old,'\s+',' '),'/','split');
>> new{:}
ans = Institution
ans = College Name

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by