Removing Part of A String

Hi, I have a string of numbers of in the format '7646 89:89'. I basically want to remove the numbers following the white space e.g I want '7646 89:89' to become '7649'. Thanks

 Akzeptierte Antwort

Fangjun Jiang
Fangjun Jiang am 27 Dez. 2011

0 Stimmen

s='7646 89:89';
d=textscan(s,'%f*');
d=d{1};

1 Kommentar

Jan
Jan am 27 Dez. 2011
TEXTSCAN is very powerful, and in consequence it is slow.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Jan
Jan am 27 Dez. 2011

0 Stimmen

Faster than the very powerful TEXTSCAN:
s = '7646 89:89';
d = strtok(s, ' ');
Or simply:
d = strtok(s);
Or:
index = strfind(s, ' ');
d = s(1:index(1));

Kategorien

Mehr zu Characters and Strings finden Sie in Hilfe-Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by