find the matching strings in tables
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Birsen
am 23 Sep. 2016
Bearbeitet: Walter Roberson
am 24 Sep. 2016
Hi,
I have an excel file and I converted to a table. My table has a column called "Locations". The location column contains a long list of string like " Country1-Area1,CityA-52". I would like to rename the sites as follows: Area1,CityA-52. I tried many things to find the first "-" index number in a table. I thought if I find the first index number then I could read the rest of the string. Could not succeed so far. Since it is a table it is more complicated. Any ideas?
Thank you Birsen
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 24 Sep. 2016
YourTable.Locations = regexprep( YourTable.Locations, '^[^-]+-', '', 'lineanchors');
2 Kommentare
Weitere Antworten (2)
George
am 24 Sep. 2016
a = 'Country1-Area1,CityA-52';
expression = '-.+$'; % a dash, one or more characters until the end of the line
[token, ~] = regexp(a, expression, 'match');
token{1}(2:end) % lop off the dashes
ans =
1×11 char array
Area1,CityA-52
Image Analyst
am 24 Sep. 2016
What about using the strrep() function? If you'd given code for making a demo table, I might have tried it for you. You gotta make it easy for us, or at least that helps.
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!