Telling numbers and letters apart

2 ビュー (過去 30 日間)
GIOELE BORDIN
GIOELE BORDIN 2024 年 3 月 31 日
コメント済み: GIOELE BORDIN 2024 年 3 月 31 日
Hi!
I have to run a script to check a character in a string is a letter or a number, but i dont know how. Can someone help me?
Basically I get lines of raw data that look like this, a letter followed by 4 numbers:
A3324B4543
C3435F3455
Z2334G3455
Sometimes (about ~1/200 elements) i get a wrong one, that is either too long, too short, or has letter and numbers in the wrong order, like:
D56788T5434
E44G5555
1D345G5679
I can easily filter out the first two by checking the lenght of the string, but i am unable to filter out the third kind of error.
I'm grateful for all of the help you can give me

採用された回答

Steven Lord
Steven Lord 2024 年 3 月 31 日
You can use the isstrprop function to determine which characters inside a string are letters.
S = ["D56788T5434"
"E44G5555"
"1D345G5679"]
L = isstrprop(S, 'alpha')
I assume the reason you object to the third string is that it doesn't start with a letter?
startsWithLetter = L{3}(1) % false
  1 件のコメント
GIOELE BORDIN
GIOELE BORDIN 2024 年 3 月 31 日
Thank you very much! the isstrprop function is exactly what i need

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by