detect nth character in a string

hello all masters,
i have a variable string for example a = 'c13Maya'
how do i detect the 2nd and 3rd characters of the string ?? the result will give 13 as answer..
any suggestion will be appreciated
thank u,
-Maya-

 Akzeptierte Antwort

Dr. Seis
Dr. Seis am 22 Jan. 2012

1 Stimme

If you want the result to also be a string, then:
b = a(2:3);
If you want the result to be a number, then:
b = str2double(a(2:3));

4 Kommentare

Walter Roberson
Walter Roberson am 22 Jan. 2012
str2double() is better than str2num(): str2num invokes eval() which is expensive and fragile for this purpose. For example if the two characters happened to be '!3' then str2num would attempt to invoke a program named "3" at the operating system level.
Rusmaya Luthfina
Rusmaya Luthfina am 22 Jan. 2012
Yippy!! that's what i want! :D
thx u Mr grant..
Rusmaya Luthfina
Rusmaya Luthfina am 22 Jan. 2012
it's just fine with string result.. but anyway, thank u for the information u give me Mr. Roberson, it's very useful.. :D
Dr. Seis
Dr. Seis am 22 Jan. 2012
edit made

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

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

Community Treasure Hunt

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

Start Hunting!

Translated by